< Summary

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

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%10100%
Dispose()100%100%
CreateLogger(...)100%10100%

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    {
 9        internal static readonly ILoggerProvider LogProvider = new LogProvider();
 10        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)
 17        {
 18            Logger = logger;
 19        }
 20    }
 21
 22    internal class LogProvider : ILoggerProvider
 23    {
 124        private readonly ConcurrentDictionary<string, PassThroughLogger> _loggers = new();
 25
 26        public void Dispose()
 027        {
 028            _loggers.Clear();
 029        }
 30
 31        public ILogger CreateLogger(string categoryName)
 40432        {
 41933            return _loggers.GetOrAdd(categoryName, name => new PassThroughLogger(name));
 40434        }
 35    }
 36}