1

以下是包含简单日志文件目标的简单 nlog 配置。我的问题是如何为 Nlog.Targets.Redis 添加目标?

<targets>
  <target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
4

1 回答 1

0

以下是 NLog.Targets.Redis 的正确配置。如果您使用 nuget 获取包,请注意 nuget 安装了错误的 NLog 版本,因此您应该像下面这样放置dependentAssembly 部分。

<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
  </configSections>
  <runtime>
    <dependentAssembly>
      <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="en-us"     />
      <bindingRedirect oldVersion="2.0.0.0" newVersion="2.0.1.2" />
    </dependentAssembly>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c"     culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
    <extensions>
      <add assembly="NLog.Targets.Redis" />
    </extensions>
    <targets>
      <target name="redis" type="Redis" host="192.168.56.2" key="logstash" />
    </targets>
    <rules>
      <logger name="*" minlevel="Info" writeTo="redis" />
    </rules>
  </nlog>
</configuration>
于 2013-09-25T15:33:59.450 回答