Вопрос

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