我正在尝试创建2个记录器(使用NLog)
trace
)以下是配置
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile"
xsi:type="File"
layout="${longdate} ${level} ${threadid} ${callsite} ${message}"
fileName="${basedir}\Logs\GatewayApplicationDebugAndErrorLog.txt"
archiveNumbering="Rolling"
maxArchiveFiles="10"
archiveAboveSize="10000000"/>
<target name="J1939Trace"
xsi:type="File"
layout="${longdate} ${level} ${threadid} ${callsite} ${message}"
fileName="${basedir}\Logs\J1939Trace.txt"
archiveNumbering="Rolling"
maxArchiveFiles="10"
archiveAboveSize="10000000"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="J1939Trace" maxlevel="Trace" writeTo="J1939Trace" final="true" />
</rules>
用法如下所示
private readonly Logger logger = LogManager.GetCurrentClassLogger(); // Generic Logger
private readonly Logger j1939Logger = LogManager.GetLogger("J1939Trace"); // Specific Logger.
我观察到的是特定记录器项也记录在通用日志项中,我不希望重复。有什么想法我做错了什么?
答案 0 :(得分:1)
这会有用吗?
来自:NLog: How to exclude specific loggers from a specific rule?
添加final =&#34; true&#34;表示不会为&#34; SpammyLogger&#34;生成的事件执行更多规则,但它仅适用于指定的级别。(参见https://github.com/nlog/nlog/wiki/Configuration-file#rules)
请务必仔细阅读答案中的所有评论。