< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Logging.LoggerConfigurationExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Logging/LoggerConfigurationExtensions.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
55%
Covered lines: 5
Uncovered lines: 4
Coverable lines: 9
Total lines: 42
Line coverage: 55.5%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
NewEnsureSwitch(...)100%210%
Register(...)100%11100%
EnsureSwitch(...)100%210%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Logging/LoggerConfigurationExtensions.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using Serilog;
 3using Serilog.Core;
 4using Serilog.Events;
 5
 6namespace Kestrun.Logging;
 7
 8/// <summary>
 9/// Convenience extensions for hooking Serilog loggers into <see cref="LoggerManager"/>.
 10/// </summary>
 11public static class LoggerConfigurationExtensions
 12{
 113    private static readonly ConcurrentDictionary<LoggerConfiguration, LoggingLevelSwitch> _switches = new();
 14
 15    private static LoggingLevelSwitch NewEnsureSwitch(LoggerConfiguration config, LogEventLevel initial = LogEventLevel.
 016           => _switches.GetOrAdd(config, _ => new LoggingLevelSwitch(initial));
 17    /// <summary>
 18    /// Create a logger from this configuration and register it by name.
 19    /// </summary>
 20    public static Serilog.ILogger Register(this LoggerConfiguration config, string name, bool setAsDefault = false)
 21    {
 122        var logger = config.CreateLogger();
 123        _ = _switches.TryRemove(config, out var levelSwitch);
 24
 125        _ = LoggerManager.Register(name, logger, setAsDefault, levelSwitch);
 26
 127        return logger;
 28    }
 29
 30    /// <summary>
 31    /// Ensure that the logger configuration has a logging level switch controlling its minimum level.
 32    /// </summary>
 33    /// <param name="config">The logger configuration to modify.</param>
 34    /// <param name="initial">The initial minimum level for the switch.</param>
 35    /// <returns>The modified logger configuration.</returns>
 36    public static LoggerConfiguration EnsureSwitch(this LoggerConfiguration config, LogEventLevel initial = LogEventLeve
 37    {
 038        var levelSwitch = NewEnsureSwitch(config, initial);
 039        _ = config.MinimumLevel.ControlledBy(levelSwitch);
 040        return config;
 41    }
 42}