< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 42
Line coverage: 100%
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 08/26/2025 - 14:53:17 Line coverage: 100% (3/3) Total lines: 19 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743109/07/2025 - 04:51:39 Line coverage: 55.5% (5/9) Total lines: 42 Tag: Kestrun/Kestrun@461ff737fcae3442df54fb34b135b2349f239c4f12/15/2025 - 04:25:23 Line coverage: 100% (9/9) Total lines: 42 Tag: Kestrun/Kestrun@e333660af9731cab5ae4c14a12f3bb84a8fabc7d

Metrics

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

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.
 1016           => _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    {
 922        var logger = config.CreateLogger();
 923        _ = _switches.TryRemove(config, out var levelSwitch);
 24
 925        _ = LoggerManager.Register(name, logger, setAsDefault, levelSwitch);
 26
 927        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    {
 538        var levelSwitch = NewEnsureSwitch(config, initial);
 539        _ = config.MinimumLevel.ControlledBy(levelSwitch);
 540        return config;
 41    }
 42}