使用log4net丢弃范围内的几个日志级别 [英] Discarding several log levels within a range with log4net
问题描述
说我将log4net记录器的minLevel
和maxLevel
分别设置为FATAL
和DEBUG
,但是在某些情况下,我想忽略以WARN
级别编写的日志项,并保留所有活动范围内的其他级别.
Say I set my log4net logger's minLevel
and maxLevel
to FATAL
and DEBUG
respectively, but under some scenario I want to mute the log-items written in the WARN
level, and keep all the other levels in the range active.
是否可以以某种方式使用日志级别的离散"级别,而不是使用minLevel
和maxLevel
指定范围?
Is it possible to somehow use 'discrete' levels of log-levels rather than specifying a range using minLevel
and maxLevel
?
我认为这应该很简单,但是我还没有找到任何log4net文档或解决此问题的示例.
I assume this should be simple, but I haven't found any log4net docs or examples dealing with this issue.
推荐答案
您可以在附加程序上使用LevelMatchFilter
.
You can use the LevelMatchFilter
on your appender.
示例:
<appender name="FilteredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="DEBUG" />
</filter>
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
...
</appender>
此示例将仅打印DEBUG; INFO和ERROR消息.很容易根据您的需求进行自定义.
This example will only print DEBUG; INFO and ERROR messages. It is easy to customize this according to your needs.
注意:不要忘记最后的DenyAllFilter
.
Note: Do not forget the DenyAllFilter
at the end.
这篇关于使用log4net丢弃范围内的几个日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!