< Summary

Class:SharpHoundCommonLib.Logging
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\Logging\Logging.cs
Covered lines:2
Uncovered lines:3
Coverable lines:5
Total lines:36
Line coverage:40% (2 of 5)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%10100%
ConfigureLogging(...)100%100%

File(s)

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

#LineLine coverage
 1#nullable enable
 2using System.Collections.Concurrent;
 3using Microsoft.Extensions.Logging;
 4
 5namespace SharpHoundCommonLib
 6{
 7    internal static class Logging
 8    {
 19        internal static readonly ILoggerProvider LogProvider = new LogProvider();
 20910        internal static ILogger Logger { get; set; } = new NoOpLogger();
 11
 12        /// <summary>
 13        ///     Configures logging for the common library using an ILogger interface
 14        /// </summary>
 15        /// <param name="logger">ILogger interface desired for logging</param>
 16        internal static void ConfigureLogging(ILogger logger)
 017        {
 018            Logger = logger;
 019        }
 20    }
 21
 22    internal class LogProvider : ILoggerProvider
 23    {
 24        private readonly ConcurrentDictionary<string, PassThroughLogger> _loggers = new();
 25
 26        public void Dispose()
 27        {
 28            _loggers.Clear();
 29        }
 30
 31        public ILogger CreateLogger(string categoryName)
 32        {
 33            return _loggers.GetOrAdd(categoryName, name => new PassThroughLogger(name));
 34        }
 35    }
 36}