| | 1 | | #nullable enable |
| | 2 | | using System.Collections.Concurrent; |
| | 3 | | using Microsoft.Extensions.Logging; |
| | 4 | |
|
| | 5 | | namespace SharpHoundCommonLib |
| | 6 | | { |
| | 7 | | internal static class Logging |
| | 8 | | { |
| 1 | 9 | | internal static readonly ILoggerProvider LogProvider = new LogProvider(); |
| 209 | 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) |
| 0 | 17 | | { |
| 0 | 18 | | Logger = logger; |
| 0 | 19 | | } |
| | 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 | | } |