예제 #1
0
        private void UpdateOptions(BatchingLoggerOptions options)
        {
            var oldIsEnabled = IsEnabled;

            IsEnabled      = options.IsEnabled;
            _includeScopes = options.IncludeScopes;

            if (oldIsEnabled != IsEnabled)
            {
                if (IsEnabled)
                {
                    Start();
                }
                else
                {
                    Stop();
                }
            }
        }
예제 #2
0
        protected BatchingLoggerProvider(IOptionsMonitor <BatchingLoggerOptions> options)
        {
            // NOTE: Only IsEnabled and IncludeScopes are monitored

            _loggerOptions = options.CurrentValue;
            if (_loggerOptions.BatchSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(_loggerOptions.BatchSize), $"{nameof(_loggerOptions.BatchSize)} must be a positive number.");
            }
            if (_loggerOptions.FlushPeriod <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(_loggerOptions.FlushPeriod), $"{nameof(_loggerOptions.FlushPeriod)} must be longer than zero.");
            }

            //_filter = _loggerOptions.LogLevel;
            _interval  = _loggerOptions.FlushPeriod;
            _batchSize = _loggerOptions.BatchSize;
            _queueSize = _loggerOptions.BackgroundQueueSize;

            _optionsChangeToken = options.OnChange(UpdateOptions);
            UpdateOptions(options.CurrentValue);
        }