private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case "ErrorEnabled": case "WarnEnabled": case "InfoEnabled": case "DebugEnabled": case "DiagEnabled": if (ErrorEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Error); loggingRule.EnableLoggingForLevel(NLog.LogLevel.Fatal); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Error); loggingRule.DisableLoggingForLevel(NLog.LogLevel.Fatal); } if (WarnEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Error); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Error); } if (InfoEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Info); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Info); } if (DebugEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Debug); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Debug); } if (DiagEnabled) { loggingRule.EnableLoggingForLevel(NLog.LogLevel.Trace); } else { loggingRule.DisableLoggingForLevel(NLog.LogLevel.Trace); } LogManager.ReconfigExistingLoggers(); break; } }
private void ConfigureCaptureTarget() { captureTarget = new CaptureTarget { Layout = "${date}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}" }; captureTarget.LogReceived += target_LogReceived; var asyncWrapper = new AsyncTargetWrapper { Name = "CaptureTargetWrapper", WrappedTarget = captureTarget }; LogManager.Configuration.AddTarget(asyncWrapper.Name, asyncWrapper); currentLogLevel = NLog.LogLevel.Info; loggingRule = new LoggingRule("*", currentLogLevel, asyncWrapper); LogManager.Configuration.LoggingRules.Insert(0, loggingRule); LogManager.ReconfigExistingLoggers(); PropertyChanged += OnPropertyChanged; #if DEBUG DebugEnabled = true; #endif }