Reputation: 3476
NLog 4.6.6
I have tried everything to get a specific logger disabled and can't get it to work. I'm wondering if it's a bug in NLog. Based on documentation:
There is one more level, Off. Since it is the highest value and is not used for entries, it disables logging when used as the minimum log level.
and:
In case a rule is marked as final and contains any level-declaring attributes, the final attribute applies only to the specified levels.
So if I do the internet-recommended route (even this SO answer), it still gets logged.
<logger name="Example.*" minlevel="Off" final="true" />
<logger name="*" minlevel="Trace" writeTo="file" />
It is important for the answer to show the logger as disabled -- in order to short-circuit expensive debug code -- and not just dump it into the Null
target.
Upvotes: 3
Views: 2321
Reputation: 3476
A little farther down on the documentation linked in the question in the examples, there is this:
<logger name="Name.Space.*" minlevel="Debug" maxlevel="Error" final="true" /> <logger name="*" writeTo="f1" />
Configures to ignore messages from any class in the Name.Space namespace with level between Debug and Error (which is Debug, Info, Warn, Error). The first rule selects loggers, but since there is no writeTo, these messages are not logged. And, since this rule contains 'final=true', the last rule does not apply to loggers matching the first rule.
I tried the following and it worked:
<logger name="Example.*" minlevel="Trace" final="true" />
<logger name="*" minlevel="Trace" writeTo="file" />
The key was to just specify the lowest level (Trace
) as minlevel
, not Off
. And that matches the rules of what the documentation says.
I'm guessing this has changed over the versions and hence the confusion.
Upvotes: 4