NLog:如何从特定规则中排除特定记录器? [英] NLog: How to exclude specific loggers from a specific rule?
问题描述
在我的NLog配置中,我有一个包罗万象的记录器,但是我创建的特定记录器非常垃圾,我希望其输出转到自己的文件中.这部分很容易,但是全面记录器也会收到垃圾日志消息.我如何告诉主记录器记录除排除垃圾记录器之外的所有记录?
In my NLog configuration, I have a catch-all logger but a specific logger I have created is very spammy and I want its output to go to its own file. That part is easy, but the catch-all logger receives the spammy log messages as well. How do I tell the main logger to log everything but to exclude the spammy logger?
我正在使用NLog 2.0.
I'm using NLog 2.0.
推荐答案
我认为您想要这样的东西:
I think something like this is what you want:
<logger name="SpammyLogger" minlevel="Off" maxlevel="Trace" final="true" />
<logger name="SpammyLogger" minlevel="Debug" maxlevel="Fatal" writeTo="SpammyFileTarget" final="true" />
<logger name="*" levels="Trace" writeTo="RegularFileTarget/" />
添加final="true"
意味着将不再对"SpammyLogger"
产生的事件执行任何规则,但仅适用于指定级别.(请参阅
Adding final="true"
means that no more rules will be executed for the events produced by "SpammyLogger"
, but it applies only to the specified levels.(see https://github.com/nlog/nlog/wiki/Configuration-file#rules)
有关更多NLog信息的信息,请参见以下链接:
See this link for more NLog info that you might find helpful:
这篇关于NLog:如何从特定规则中排除特定记录器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!