public DBLoggerProvider(string connectionString, string logLevel, BatchingLoggerOptions loggerOptions) { if (!Enum.TryParse(logLevel, out _logLevel)) { _logLevel = LogLevel.Warning; } var optionsBuilder = new DbContextOptionsBuilder <managerDbContext>(); optionsBuilder.UseMySQL(connectionString); _managerDbContext = new managerDbContext(optionsBuilder.Options); 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."); } _interval = loggerOptions.FlushPeriod; _batchSize = loggerOptions.BatchSize; _queueSize = loggerOptions.BackgroundQueueSize; Start(); }
public void InitializesIsEnabled(bool?enabled) { var configuration = new ConfigurationBuilder().AddInMemoryCollection(new[] { new KeyValuePair <string, string>("IsEnabledKey", enabled?.ToString()) }).Build(); var options = new BatchingLoggerOptions(); new BatchLoggerConfigureOptions(configuration, "IsEnabledKey").Configure(options); Assert.Equal(enabled ?? false, options.IsEnabled); }
private void UpdateOptions(BatchingLoggerOptions options) { var oldIsEnabled = IsEnabled; IsEnabled = options.IsEnabled; _includeScopes = options.IncludeScopes; if (oldIsEnabled != IsEnabled) { if (IsEnabled) { Start(); } else { Stop(); } } }