Ejemplo n.º 1
0
 public FileLoggerProvider(
     IFileManager fileManager,
     IHttpContextAccessor accessor,
     ILogSetting logSetting,
     Func <string, LogLevel, bool> filter) : this(fileManager, accessor, logSetting, filter, null)
 {
 }
Ejemplo n.º 2
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.
                _logSetting = _logSetting.Reload();

                var includeScopes = _logSetting?.IncludeScopes ?? false;
                foreach (var logger in _loggers.Values)
                {
                    if (_isLegacy)
                    {
                        logger.Filter = GetFilter(logger.Name);
                    }
                    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 (_logSetting?.ChangeToken != null)
                {
                    _logSetting.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
                }
            }
        }
Ejemplo n.º 3
0
 public static ILoggerFactory AddFileLogger(
     this ILoggerFactory factory,
     IFileManager fileManager,
     IHttpContextAccessor accessor,
     ILogSetting settings)
 {
     factory.AddProvider(new FileLoggerProvider(fileManager, accessor, settings));
     return(factory);
 }
Ejemplo n.º 4
0
 public FileLoggerProvider(
     IFileManager fileManager,
     IHttpContextAccessor accessor,
     ILogSetting logSetting,
     Func <string, LogLevel, bool> filter,
     string dirPath)
 {
     _filter      = filter;
     _fileManager = fileManager;
     _accessor    = accessor;
     _logSetting  = logSetting;
     _dirPath     = string.IsNullOrEmpty(dirPath) ? Path.Combine(AppContext.BaseDirectory, "Log") : dirPath;
     if (_logSetting.ChangeToken != null)
     {
         logSetting.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
     }
 }
Ejemplo n.º 5
0
        public FileLoggerProvider(IFileManager fileManager, IHttpContextAccessor accessor, IConfiguration configuration)
        {
            if (configuration != null)
            {
                _logSetting = new ConfigurationFileLogSetting(configuration);

                if (_logSetting.ChangeToken != null)
                {
                    _logSetting.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
                }
            }
            else
            {
                _logSetting = new BaseLogSetting();
            }

            _fileManager = fileManager;
            _accessor    = accessor;
            _dirPath     = Path.Combine(AppContext.BaseDirectory, "Log");
            _isLegacy    = false;
        }
Ejemplo n.º 6
0
 public FileLoggerProvider(IFileManager fileManager,
                           IHttpContextAccessor accessor,
                           ILogSetting logSetting) : this(fileManager, accessor, logSetting, null)
 {
     _isLegacy = true;
 }