Search code examples
configurationnlog

What does nlog maxLevel=off config option do when combined with other configuration targeting the same output?


I'm unsure of what the nlog "level=off" config option does when combined with other configuration targeting the same output like the config provided below:

<logger name="Name.Space.*" minLevel="Info" writeTo="console" final="true"/>
<logger name="Name.Space.*" maxLevel="off" writeTo="console" final="true"/>

What behaviour would such a configuration would achieve?


Solution

  • This means all logger output with LogLevel above minLevel="Info" (Info + Warn + Error + Fatal) should writeTo="console", and because of final="true" then logger-output should not reach following rules:

    <logger name="Name.Space.*" minLevel="Info" writeTo="console" final="true"/>
    

    This means all logger output with LogLevel below maxLevel="off" (Trace + Debug + Info + Warn + Error + Fatal) should writeTo="console", and because of final="true" then logger-output should not reach following rules:

    <logger name="Name.Space.*" maxLevel="off" writeTo="console" final="true"/>
    

    The result of using these two rules, is that all output coming from Logger-instances matching name="Name.Space.*" will writeTo="console" independent of LogLevel.

    maxLevel is usually used to suppress logging. Because many find the maxLevel somewhat confusing, then NLog v5 have now introduced the new finalMinLevel.

    Maybe you want to do this:

    <logger name="Name.Space.*" minLevel="Info" writeTo="console" finalMinLevel="Off" />