Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog and final rules

Tags:

.net

nlog

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&lt;=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.

like image 374
John Avatar asked May 17 '13 17:05

John


1 Answers

Try this:

<logger name="ChattyLogger" maxlevel="Warn"/>
<logger name="ChattyLogger" minlevel="Error" final="true" writeTo="default"/>
<logger name="*" minlevel="Info" writeTo="default" />
like image 117
Alex Filipovici Avatar answered Nov 10 '22 08:11

Alex Filipovici