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.
Is it possible to somehow use 'discrete' levels of log-levels rather than specifying a range using minLevel
and maxLevel
?
I assume this should be simple, but I haven't found any log4net docs or examples dealing with this issue.
You can use the LevelMatchFilter
on your appender.
Example:
<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>
This example will only print DEBUG; INFO and ERROR messages. It is easy to customize this according to your needs.
Note: Do not forget the DenyAllFilter
at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With