< Summary

Class:SharpHoundCommonLib.PassThroughLogger
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\Logging\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\Logging\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
 1514        public PassThroughLogger(string name)
 1515        {
 1516            _name = name;
 1517        }
 18
 19        public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
 20            Func<TState, Exception, string> formatter)
 20621        {
 20622            var newLog = FormatLog(formatter(state, exception), exception);
 20623            Logging.Logger.Log(logLevel, newLog);
 20624        }
 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)
 20637        {
 20638            return $"[CommonLib {_name}]{message}{(e != null ? $"\n{e}" : "")}";
 20639        }
 40    }
 41}