| | 1 | | #nullable enable |
| | 2 | | using System.Collections.Concurrent; |
| | 3 | | using Microsoft.Extensions.Logging; |
| | 4 | |
|
| | 5 | | namespace 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 | | { |
| 1 | 24 | | private readonly ConcurrentDictionary<string, PassThroughLogger> _loggers = new(); |
| | 25 | |
|
| | 26 | | public void Dispose() |
| 0 | 27 | | { |
| 0 | 28 | | _loggers.Clear(); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | public ILogger CreateLogger(string categoryName) |
| 404 | 32 | | { |
| 419 | 33 | | return _loggers.GetOrAdd(categoryName, name => new PassThroughLogger(name)); |
| 404 | 34 | | } |
| | 35 | | } |
| | 36 | | } |