为什么NLog配置更改不生效?

时间:2012-07-03 08:56:43

标签: nlog nlog-configuration

我尝试通过以下方式更改NLog的配置:

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

但是它默默地忽略了我的变化。但是,当我尝试

SimpleConfigurator.ConfigureForTargetLogging (this, level);

它立即起作用 - 但丢弃了之前的所有配置。为什么会这样,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

SimpleConfigurator取代了当前配置,因此您无法将其用于聚合案例。

除非您通过LogManager.Configuration = new_config通知,否则NLog不会检测并遵循对其当前配置所做的更改。所以请改用它:

var conf = LogManager.Configuration;
conf.AddTarget (name, foo);
conf.LoggingRules.Add (new LoggingRule ("*", LogLevel.Trace, foo));
LogManager.Configuration = conf;
相关问题