Excludes certain loggers using the rule in nlog programmatically

I am considering a way to implement the following logging rule programmatically.

<logger name="Name.Space.*" minlevel="Debug" maxlevel="Error" final="true" /> 

I can use the following to set "name" and "loglevel", but there is no way to implement final = "true".

 LoggingRule fileLoggingRule = new LoggingRule("ConnDriverLogger", LogLevel.Trace, connDriverFileTarget); connDriverLoggingConfig.LoggingRules.Add(fileLoggingRule); 

Any suggestions for implementing the above?

+4
source share
1 answer

What about the LoggingRule.Final property?

In your case:

 LoggingRule fileLoggingRule = new LoggingRule("ConnDriverLogger", LogLevel.Trace, connDriverFileTarget); fileLoggingRule.Final = true; connDriverLoggingConfig.LoggingRules.Add(fileLoggingRule); 

I found the LoggingRule.Final property here in the NLog repository:

https://github.com/NLog/NLog/blob/master/src/NLog/Config/LoggingRule.cs

+5
source

All Articles