< Summary

Class:SharpHoundCommonLib.PassThroughLogger
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\PassThroughLogger.cs
Covered lines:11
Uncovered lines:6
Coverable lines:17
Total lines:41
Line coverage:64.7% (11 of 17)
Covered branches:2
Total branches:2
Branch coverage:100% (2 of 2)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%10100%
Log(...)100%10100%
IsEnabled(...)100%100%
BeginScope(...)100%100%
FormatLog(...)100%20100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\PassThroughLogger.cs

#LineLine coverage
 1using System;
 2using Microsoft.Extensions.Logging;
 3
 4namespace SharpHoundCommonLib
 5{
 6    /// <summary>
 7    ///     ILogger implementation that passes log entries through to the configured ILogger and prepends an identificat
 8    ///     string
 9    /// </summary>
 10    internal class PassThroughLogger : ILogger
 11    {
 12        private readonly string _name;
 13
 1414        public PassThroughLogger(string name)
 1415        {
 1416            _name = name;
 1417        }
 18
 19        public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
 20            Func<TState, Exception, string> formatter)
 25221        {
 25222            var newLog = FormatLog(formatter(state, exception), exception);
 25223            Logging.Logger.Log(logLevel, newLog);
 25224        }
 25
 26        public bool IsEnabled(LogLevel logLevel)
 027        {
 028            return true;
 029        }
 30
 31        public IDisposable BeginScope<TState>(TState state)
 032        {
 033            return default;
 034        }
 35
 36        private string FormatLog(string message, Exception e)
 25237        {
 25238            return $"[CommonLib {_name}]{message}{(e != null ? $"\n{e}" : "")}";
 25239        }
 40    }
 41}