Ejemplo n.º 1
0
        public FileLoggerProcessor(IOptionsMonitor <W3CLoggerOptions> options, IHostEnvironment environment, ILoggerFactory factory)
        {
            _logger = factory.CreateLogger(typeof(FileLoggerProcessor));

            _options = options;
            var loggerOptions = _options.CurrentValue;

            _path = loggerOptions.LogDirectory;
            // If user supplies no LogDirectory, default to {ContentRoot}/logs.
            // If user supplies a relative path, use {ContentRoot}/{LogDirectory}.
            // If user supplies a full path, use that.
            if (string.IsNullOrEmpty(_path))
            {
                _path = Path.Join(environment.ContentRootPath, "logs");
            }
            else if (!Path.IsPathRooted(_path))
            {
                _path = Path.Join(environment.ContentRootPath, _path);
            }

            _fileName         = loggerOptions.FileName;
            _maxFileSize      = loggerOptions.FileSizeLimit;
            _maxRetainedFiles = loggerOptions.RetainedFileCountLimit;
            _flushInterval    = loggerOptions.FlushInterval;
            _fields           = loggerOptions.LoggingFields;
            _options.OnChange(options =>
            {
                lock (_pathLock)
                {
                    // Clear the cached settings.
                    loggerOptions = options;

                    // Move to a new file if the fields have changed
                    if (_fields != loggerOptions.LoggingFields)
                    {
                        _fileNumber++;
                        if (_fileNumber >= W3CLoggerOptions.MaxFileCount)
                        {
                            _maxFilesReached = true;
                            Log.MaxFilesReached(_logger);
                        }
                        _fields = loggerOptions.LoggingFields;
                    }

                    if (!string.IsNullOrEmpty(loggerOptions.LogDirectory))
                    {
                        _path = loggerOptions.LogDirectory;
                    }

                    _fileName         = loggerOptions.FileName;
                    _maxFileSize      = loggerOptions.FileSizeLimit;
                    _maxRetainedFiles = loggerOptions.RetainedFileCountLimit;
                    _flushInterval    = loggerOptions.FlushInterval;
                }
            });

            // Start message queue processor
            _cancellationTokenSource = new CancellationTokenSource();
            _outputTask = Task.Run(ProcessLogQueue);
        }
Ejemplo n.º 2
0
 public W3CLogger(IOptionsMonitor <W3CLoggerOptions> options, IHostEnvironment environment, ILoggerFactory factory)
 {
     _options       = options;
     _loggingFields = _options.CurrentValue.LoggingFields;
     _options.OnChange(options =>
     {
         _loggingFields = options.LoggingFields;
     });
     _messageQueue = InitializeMessageQueue(_options, environment, factory);
 }
Ejemplo n.º 3
0
 public W3CLogger(IOptionsMonitor <W3CLoggerOptions> options, W3CLoggerProcessor messageQueue)
 {
     _options       = options;
     _loggingFields = _options.CurrentValue.LoggingFields;
     _options.OnChange(options =>
     {
         _loggingFields = options.LoggingFields;
     });
     _messageQueue = messageQueue;
 }
Ejemplo n.º 4
0
 public W3CLoggerProcessor(IOptionsMonitor <W3CLoggerOptions> options, IHostEnvironment environment, ILoggerFactory factory) : base(options, environment, factory)
 {
     _loggingFields = options.CurrentValue.LoggingFields;
 }
Ejemplo n.º 5
0
 public W3CLoggerProcessor(IOptionsMonitor <W3CLoggerOptions> options, IHostEnvironment environment, ILoggerFactory factory) : base(options, environment, factory)
 {
     _loggingFields            = options.CurrentValue.LoggingFields;
     _additionalRequestHeaders = W3CLoggerOptions.FilterRequestHeaders(options.CurrentValue);
 }