Log4net附加程序阈值不起作用 [英] Log4net appender threshold not working
问题描述
我已经在我的log4net配置中为应用程序设置了logfileAppender
和consoleAppender
.我希望日志文件附加程序只写ERROR消息及以上,而控制台附加程序写DEBUG或以上.
I've set up a logfileAppender
and a consoleAppender
in my log4net config for my application. I would like the logfile appender to only write ERROR messages and above and the console appender to write DEBUG and above.
我的配置是:
<log4net debug="false">
<appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net" >
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d %M - %m%n" />
</layout>
<threshold value="ERROR"/>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
我发现ERROR和DEBUG都正在输出到我的日志文件追加器中.如何将其限制为仅ERROR?
I'm finding that both ERROR and DEBUG is being output to my logfile appender. How to restrict it to only ERROR?
推荐答案
还要注意,记录器中的level
标记与threshold
或LevelMatchFilter
的工作方式不同.
Note also that the level
tag in the logger doesn't work the same way as threshold
or a LevelMatchFilter
.
Level
指示将实际生成的日志语句.您可以在代码中进行测试.
Level
indicates what log statements that actually will be generated. This is what you can test on in you code.
Threshold
过滤掉所有低于阈值的日志消息.
Threshold
on the other hand, filters away all log messages that falls below your threshold.
这意味着具有高于最高记录器级别的阈值是没有意义的.我已经多次看到如何设置INFO级别(因为大多数附加程序将使用该信息),然后创建一个具有DEBUG阈值的附加程序.然后,当没有任何调试消息真正出现在附加程序上时,您会感到惊讶...
This means that having a threshold that is higher than the highest logger level makes no sense. I have seen many times how one sets a level of INFO (because that is what most appenders will use), and then create an appender that has a threshold of DEBUG. And then you are surprised when no DEBUG messages actually appears on the appender...
这篇关于Log4net附加程序阈值不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!