Search code examples
nlog

NLog - disable a specific logger


I'd like to set all loggers to log to a file except one for a specific class. I can't seem to figure out how to do it. Currently I'm trying the following nlog.config

No matter what I do, the interceptor is logging

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target name="file" xsi:type="File" 
                fileName="${basedir}/logs/log.log" 
                maxArchiveFiles="1" archiveAboveSize="1000000" />
    </targets>
    <rules>
        <logger name="*" minlevel="Debug" writeTo="file" />
        <logger name="MyApp.DbInterceptionConfig+LoggingEFInterceptor" minlevel="Info" writeTo="file" />

    </rules>
</nlog>

Solution

  • Adding final="true" to the class will tell it to stop running thru the rest of the rules when that one is hit. Because of this, the order in which you define the rules may be important as well in case you wanted more then one rule to hit but not others.