hi NLoggers,
i have a problem regarding programmatically configuration of NLog, especially the rules.
My scenario: I have 3 targets, a file, the console and nlog-viewer/udp target. For each of the target i have set a rule, whereby i use the asterisk-wildcard "*" for the logger-name-pattern because all logger-names should go to the 3 targets.
Now i have a special logger-name who's target should just go to a certain file, i have also applied a rule for this and all works fine. But if i use this special logger-name, the logs go to the other 3 targets too, because of the asterisk for the name-pattern in the other rules.
How can i set a wilcard like "*" for the logger-name-pattern but exclude a certain logger-name? Is this possible? Something like "*;exclude=tcln" ?
Her's my code:
// Step 4. Define rules
LoggingRule rule1 = new LoggingRule("*", LogLevel.FromString(lfl), fileTarget);
LoggingRule rule2 = new LoggingRule("*", LogLevel.FromString(ull), viewerTarget);
LoggingRule rule3 = new LoggingRule("*", LogLevel.Info, colconsTarget);
LoggingRule rule4 = new LoggingRule(tcln, LogLevel.Trace, fileTarget2);
config.LoggingRules.Add(rule1);
config.LoggingRules.Add(rule2);
config.LoggingRules.Add(rule3);
config.LoggingRules.Add(rule4);
// Step 5. Activate the configuration
LogManager.Configuration = config;
tcln is a special logger-name who's logs should only go to target fileTarget2, however the logs also go to the other targets.
I wonder why it's only possible to direct logs to targets by using the logger-name, usually developers would use the classnames as the logger-name, independant of the targets. Isn't it easier to state the wanted target when firing a log using an overloaded method? Isn't it possible to state the target along with the loglevel when firing a target?
Thanks in advance for all hints,
frogbone