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

namespace Shared;

public class ConsoleProvider : ILoggerProvider
{

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

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

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

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

}