예제 #1
0
 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.CategoryName, _settings);
             logger.IncludeScopes = includeScopes;
         }
     }
     catch (Exception ex)
     {
         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);
         }
     }
 }
        private void OnConfigurationReload(object state)
        {
            // Creating a new settings object, because the old one is probably holding on to an old change token.
            _settings = _settings.Reload();

            if (!LogRecordCache.IsEmpty)
            {
                LogRecordCache.Flush(_writer);
            }

            LogRecordCache.SetCapacity(_settings.BulkWriteCacheSize);

            foreach (var logger in _loggers.Values)
            {
                logger.Filter   = GetFilter(logger.Category);
                logger.Settings = _settings;
            }

            // The token will change each time it reloads, so we need to register again.
            _settings?.ChangeToken?.RegisterChangeCallback(OnConfigurationReload, null);
        }