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

namespace Shared;

public class FeedbackProvider : ILoggerProvider
{

    private readonly LogLevel _LogLevel;
    private readonly IFeedback _Feedback;
    private readonly ConcurrentDictionary<string, FeedbackLogger> _Loggers;

    public FeedbackProvider(LogLevel logLevel, IFeedback feedback)
    {
        _LogLevel = logLevel;
        _Feedback = feedback;
        _Loggers = new ConcurrentDictionary<string, FeedbackLogger>();
    }

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

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

}