< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Logging.LoggerExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Logging/LoggerExtensions.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 71
Line coverage: 94.4%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 01:25:22 Line coverage: 94.4% (17/18) Branch coverage: 80% (8/10) Total lines: 71 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/06/2025 - 18:30:33 Line coverage: 94.4% (17/18) Branch coverage: 90% (9/10) Total lines: 71 Tag: Kestrun/Kestrun@aeddbedb8a96e9137aac94c2d5edd011b57ac871 08/26/2025 - 01:25:22 Line coverage: 94.4% (17/18) Branch coverage: 80% (8/10) Total lines: 71 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/06/2025 - 18:30:33 Line coverage: 94.4% (17/18) Branch coverage: 90% (9/10) Total lines: 71 Tag: Kestrun/Kestrun@aeddbedb8a96e9137aac94c2d5edd011b57ac871

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DebugSanitized(...)100%22100%
DebugSanitized(...)50%2280%
SanitizeObject(...)100%22100%
SanitizeString(...)100%44100%

File(s)

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

#LineLine coverage
 1
 2using System.Text;
 3using Serilog.Events;
 4
 5
 6namespace Kestrun.Logging;
 7
 8/// <summary>
 9/// Sanitized Serilog extensions to strip control chars (including CR/LF)
 10/// from any string property values before writing the log.
 11/// </summary>
 12public static class LoggerExtensions
 13{
 14    /// <summary>
 15    /// Writes a sanitized debug log event, removing control characters from string property values.
 16    /// </summary>
 17    /// <param name="log">The Serilog logger instance.</param>
 18    /// <param name="messageTemplate">The message template.</param>
 19    /// <param name="propertyValues">The property values for the message template.</param>
 20    public static void DebugSanitized(this Serilog.ILogger log, string messageTemplate, params object?[] propertyValues)
 21    {
 3422        if (!log.IsEnabled(LogEventLevel.Debug))
 23        {
 124            return;
 25        }
 26
 3327        var sanitized = propertyValues.Select(SanitizeObject).ToArray();
 3328        log.Debug(messageTemplate, sanitized);
 3329    }
 30
 31
 32    /// <summary>
 33    /// Writes a sanitized debug log event with an exception, removing control characters from string property values.
 34    /// </summary>
 35    /// <param name="log">The Serilog logger instance.</param>
 36    /// <param name="exception">The exception to log.</param>
 37    /// <param name="messageTemplate">The message template.</param>
 38    /// <param name="propertyValues">The property values for the message template.</param>
 39    public static void DebugSanitized(this Serilog.ILogger log, Exception exception, string messageTemplate, params obje
 40    {
 141        if (!log.IsEnabled(LogEventLevel.Debug))
 42        {
 043            return;
 44        }
 45
 146        var sanitized = propertyValues.Select(SanitizeObject).ToArray();
 147        log.Debug(exception, messageTemplate, sanitized);
 148    }
 49
 50    // Helper: sanitize only string args
 51    private static object? SanitizeObject(object? o) =>
 3952        o is string s
 3953            ? SanitizeString(s)
 3954            : o;
 55
 56    // Strip out all control characters (0x00–0x1F, 0x7F), including CR/LF
 57    private static string SanitizeString(string input)
 58    {
 359        var sb = new StringBuilder(input.Length);
 10060        foreach (var c in input)
 61        {
 4762            if (char.IsControl(c))
 63            {
 64                continue;
 65            }
 66
 4167            _ = sb.Append(c);
 68        }
 369        return sb.ToString();
 70    }
 71}