using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;

namespace Shared;

public class DebugProvider : ILoggerProvider
{

    private readonly LogLevel _LogLevel;
    private readonly ConcurrentDictionary<string, DebugLogger> _Loggers;

    public DebugProvider(LogLevel logLevel)
    {
        _LogLevel = logLevel;
        _Loggers = new ConcurrentDictionary<string, DebugLogger>();
    }

    public ILogger CreateLogger(string categoryName) => _Loggers.GetOrAdd(categoryName, name => new DebugLogger(_LogLevel, name));

    public void Dispose()
    {
        _Loggers.Clear();
        GC.SuppressFinalize(this);
    }

}