private void OnConfigurationReload(object state)
 {
     try
     {
         // The settings object needs to change here, because the old one is probably holding on
         // to an old change token.
         _settings = _settings.Reload();
         var includeScopes = _settings?.IncludeScopes ?? false;
         foreach (var logger in _loggers.Values)
         {
             logger.Filter        = GetFilter(logger.Name, _settings);
             logger.IncludeScopes = includeScopes;
         }
     }
     catch (Exception ex)
     {
         System.Console.WriteLine($"Error while loading configuration changes.{Environment.NewLine}{ex}");
     }
     finally
     {
         // The token will change each time it reloads, so we need to register again.
         if (_settings?.ChangeToken != null)
         {
             _settings.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
         }
     }
 }
 public RollingFileLoggerProvider(IRollingFileLoggerSettings settings)
 {
     //_env = env;
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
     if (_settings.ChangeToken != null)
     {
         _settings.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
     }
 }
        private Func <string, LogLevel, bool> GetFilter(string name, IRollingFileLoggerSettings settings)
        {
            if (_filter != null)
            {
                return(_filter);
            }

            if (settings != null)
            {
                foreach (var prefix in GetKeyPrefixes(name))
                {
                    LogLevel level;
                    if (settings.TryGetSwitch(prefix, out level))
                    {
                        return((n, l) => l >= level);
                    }
                }
            }

            return((n, l) => false);
        }
 /// <summary>
 /// Adds a rolling file logger that is enabled as defined in settings.
 /// (consider using the ILoggingBuilder extension instead)
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 internal static ILoggerFactory AddRollingFile(this ILoggerFactory factory, IRollingFileLoggerSettings settings)
 {
     factory.AddProvider(new RollingFileLoggerProvider(settings));
     return(factory);
 }