public static IServiceCollection AddDynamicSwitches(this IServiceCollection services, DynamicSwitchCollection collection = null) { collection ??= DynamicSwitchCollection.Current; services.TryAddSingleton(collection); return(services); }
public static LoggerConfiguration DynamicSwitch( this LoggerSinkConfiguration configuration, DynamicSwitchCollection collection, string switchName, LoggingLevelSwitch levelSwitch) { configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); switchName = !string.IsNullOrWhiteSpace(switchName) ? switchName : throw new ArgumentNullException(nameof(switchName)); levelSwitch = levelSwitch ?? throw new ArgumentNullException(nameof(levelSwitch)); collection ??= DynamicSwitchCollection.Current; if (!collection.TryAdd(switchName, levelSwitch)) { throw new ArgumentException($"Key '{switchName}' already exists."); } return(configuration.Logger(_ => { })); }