I am want to filter out messages that contain specified string. I used log4net.Filter.StringMatchFilter
but that applies to appenders only.
I'd like to filter that message on Logger level already. Something along these lines:
<logger name="MyLogger.WebServices">
<level value="Debug" />
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="do not log me" />
<acceptOnMatch value="false" />
</filter>
<appender-ref ref="file" />
<appender-ref ref="debug" />
</logger>
Is it actually possible this way? Or is there a different way to handle this situation.
Filters are for use with appenders only. If you need to filter out events for several appenders you can pre-filter using a forwardingappender. This way you avoid having to copy and paste the same filter on several appenders.
Your example would look like this:
<appender name="screeningAppender" type="log4net.Appenders.ForwardingAppender">
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="do not log me" />
<acceptOnMatch value="false" />
</filter>
<appender-ref ref="file" />
<appender-ref ref="debug" />
</appender>
<logger name="MyLogger.WebServices">
<level value="Debug" />
<appender-ref ref="screeningAppender" />
</logger>
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