< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Logging.Enrichers.ErrorRecordEnricher
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Logging/Enrichers/ErrorRecordEnricher.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
81%
Covered lines: 9
Uncovered lines: 2
Coverable lines: 11
Total lines: 55
Line coverage: 81.8%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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
get_DestructureObjects()100%11100%
.ctor()100%210%
.ctor(...)100%11100%
Enrich(...)75%44100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Logging/Enrichers/ErrorRecordEnricher.cs

#LineLine coverage
 1using Kestrun.Logging.Exceptions;
 2using Serilog.Core;
 3using Serilog.Events;
 4
 5namespace Kestrun.Logging.Enrichers;
 6
 7/// <summary>
 8/// Enriches Serilog log events with error record and invocation info from WrapperException.
 9/// </summary>
 10public class ErrorRecordEnricher : ILogEventEnricher
 11{
 12    /// <summary>
 13    /// The property name used for the error record in log events.
 14    /// </summary>
 15    public const string ERR_PROPERTY_NAME_FULL = "ErrorRecord";
 16    /// <summary>
 17    /// The property name used for the invocation info in log events.
 18    /// </summary>
 19    public const string II_PROPERTY_NAME_FULL = "InvocationInfo";
 20
 21    /// <summary>
 22    /// Gets a value indicating whether objects should be destructured when enriching log events.
 23    /// </summary>
 424    public bool DestructureObjects { get; }
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="ErrorRecordEnricher"/> class.
 28    /// </summary>
 029    public ErrorRecordEnricher()
 30    {
 031    }
 32
 33    /// <summary>
 34    /// Initializes a new instance of the <see cref="ErrorRecordEnricher"/> class with the option to destructure objects
 35    /// </summary>
 36    /// <param name="destructureObjects">Indicates whether objects should be destructured when enriching log events.</pa
 637    public ErrorRecordEnricher(bool destructureObjects) => DestructureObjects = destructureObjects;
 38
 39    /// <summary>
 40    /// Enriches the log event with error record and invocation info properties if the exception is a <see cref="Wrapper
 41    /// </summary>
 42    /// <param name="logEvent">The log event to enrich.</param>
 43    /// <param name="propertyFactory">The property factory used to create log event properties.</param>
 44    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 45    {
 346        if (logEvent.Exception is WrapperException wrapperException)
 47        {
 248            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(ERR_PROPERTY_NAME_FULL, wrapperException.ErrorRe
 249            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
 250                II_PROPERTY_NAME_FULL,
 251                wrapperException.ErrorRecordWrapper?.InvocationInfoWrapper,
 252                DestructureObjects));
 53        }
 354    }
 55}