ReconfigExistingLoggers() public static method

Loops through all loggers previously returned by GetLogger. and recalculates their target and filter list. Useful after modifying the configuration programmatically to ensure that all loggers have been properly configured.
public static ReconfigExistingLoggers ( ) : void
return void
コード例 #1
0
 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;
     }
 }
コード例 #2
0
        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
        }