public LevelOverrideMap( IDictionary <string, LoggingLevelSwitch> overrides, LogEventLevel defaultMinimumLevel, LoggingLevelSwitch defaultLevelSwitch) { if (overrides == null) { throw new ArgumentNullException(nameof(overrides)); } _defaultLevelSwitch = defaultLevelSwitch; _defaultMinimumLevel = defaultLevelSwitch != null ? LevelAlias.Minimum : defaultMinimumLevel; // Descending order means that if we have a match, we're sure about it being the most specific. _overrides = overrides .OrderByDescending(o => o.Key) .Select(o => new LevelOverride(o.Key, o.Value)) .ToArray(); }
public void GetEffectiveLevel(string context, out LogEventLevel minimumLevel, out LoggingLevelSwitch levelSwitch) { foreach (var levelOverride in _overrides) { if (context.StartsWith(levelOverride.ContextPrefix) || context == levelOverride.Context) { minimumLevel = LevelAlias.Minimum; levelSwitch = levelOverride.LevelSwitch; return; } } minimumLevel = _defaultMinimumLevel; levelSwitch = _defaultLevelSwitch; }
public LevelOverride(string context, LoggingLevelSwitch levelSwitch) { Context = context; ContextPrefix = context + "."; LevelSwitch = levelSwitch; }