Beispiel #1
0
        private void ReloadConfigurationSection(IConfigurationSection nlogConfig)
        {
            try
            {
                if (!_autoReload)
                {
                    return; // Should no longer react to reload events
                }

                InternalLogger.Info("Reloading NLogLoggingConfiguration...");
                var newConfig = new NLogLoggingConfiguration(nlogConfig, LogFactory);
                var oldConfig = LogFactory.Configuration;
                if (oldConfig != null)
                {
                    if (LogFactory.KeepVariablesOnReload)
                    {
                        foreach (var variable in oldConfig.Variables)
                        {
                            newConfig.Variables[variable.Key] = variable.Value;
                        }
                    }
                    LogFactory.Configuration = newConfig;
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Warn(ex, "NLogLoggingConfiguration failed to reload");
                MonitorForReload(nlogConfig); // Continue watching this file
            }
        }
        private LoggingConfiguration ReloadLoggingConfiguration(IConfigurationSection nlogConfig)
        {
            var newConfig = new NLogLoggingConfiguration(LogFactory, nlogConfig);

            newConfig.PrepareForReload(this);   // Ensure KeepVariablesOnReload works as intended
            newConfig.LoadConfigurationSection(nlogConfig);
            return(newConfig);
        }