以下是包含简单日志文件目标的简单nlog配置。我的问题是如何为Nlog.Targets.Redis添加目标?
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
答案 0 :(得分: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>