سؤال

I tried to change NLog's configuration via:

LogManager.Configuration.AddTarget (name, foo);
LogManager.Configuration.LoggingRules.Add (new LoggingRule ("*", LogLevel.Trace, foo));

but it silently ignored my changes. However, when I tried

SimpleConfigurator.ConfigureForTargetLogging (this, level);

it worked right away - but discarded all previous configuration. Why is that, and how do I solve this?

هل كانت مفيدة؟

المحلول

SimpleConfigurator replaces the current configuration, so you cannot use it for aggregated cases.

NLog does not detect and follow changes made to its current configuration unless you notify it via LogManager.Configuration = new_config. So use this instead:

var conf = LogManager.Configuration;
conf.AddTarget (name, foo);
conf.LoggingRules.Add (new LoggingRule ("*", LogLevel.Trace, foo));
LogManager.Configuration = conf;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top