Very often I want to exclude logging from a specific chatty logger up to a certain level. Unfortunately, the first of the following rules is final for all levels of that logger, so that the second rule (which is simply my default rule) will not log anything from it:
<logger name="ChattyLogger" maxlevel="Warn" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Info" writeTo="default" />
One possibility is to use filters instead:
<logger name="ChattyLogger" writeTo="blackhole">
<filters>
<when condition="level<=LogLevel.Warn" action="IgnoreFinal" />
</filters>
</logger>
<logger name="*" minlevel="Info" writeTo="default" />
But the syntax is ugly, especially the length and the need to escape the condition expression.
Since this seems like such a common requirement, I'm wondering if I overlooked something.
I'm using nlog under Silverlight, but I presume that shouldn't matter.
Try this:
<logger name="ChattyLogger" maxlevel="Warn"/>
<logger name="ChattyLogger" minlevel="Error" final="true" writeTo="default"/>
<logger name="*" minlevel="Info" writeTo="default" />
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