I had
<logger name="*" minlevel="Trace" writeTo="f1" />
Now I added the maxlevel. so
<logger name="*" minlevel="Trace" maxlevel="Error" writeTo="f1" />
I want to implement it programmatically. What I tried
Then in code:
var filter = new ConditionBasedFilter();
filter.Action = FilterResult.Log;
filter.Condition = "(level <= LogLevel.Info)";
var loggerRule = new LoggingRule(ruleName, LogLevel.Debug, target);
loggerRule.Filters.Add(filter);
nLogLoggingConfiguration.LoggingRules.Add(loggerRule);
But the filter is not working, because the result is same as if I don't add the filter. Which means whether I comment out the line loggerRule.Filters.Add(filter);
or not, I get the same outcome.
EDIT:
It maybe the bug of NLOG. When you set up filter.Action = FilterResult.Log;
and var loggerRule = new LoggingRule(ruleName, LogLevel.Debug, target);
.
The condition cannot be applied to the rule.
We can do the following: