using Microsoft.Extensions.Logging.Abstractions;

namespace adas_core.Logging;

public static class LogProvider
{
    private static ILoggerFactory? _loggerFactory;

    /// <summary>
    ///     Sets the current log provider based on logger factory.
    /// </summary>
    /// <param name="loggerFactory">The logger factory.</param>
    public static void SetLogProvider(ILoggerFactory loggerFactory)
    {
        _loggerFactory = loggerFactory;
    }

    public static ILogger CreateLogger(string category)
    {
        if (_loggerFactory != null) return _loggerFactory.CreateLogger(category);

        return NullLogger.Instance;
    }

    public static ILogger<T> CreateLogger<T>()
    {
        if (_loggerFactory != null) return _loggerFactory.CreateLogger<T>();

        return NullLogger<T>.Instance;
    }

#if DIAGNOSTICS_SOURCE
        internal static class Cached
        {
            internal static readonly System.Lazy<System.Diagnostics.DiagnosticListener> Default =
                new(() => new System.Diagnostics.DiagnosticListener(DiagnosticHeaders.DefaultListenerName));
        }
#endif
}