using Microsoft.Extensions.Logging;
using Serilog;

namespace ZB.MOM.WW.CBDD.Tests.Benchmark;

internal static class Logging
{
    private static readonly Lazy<ILoggerFactory> LoggerFactoryInstance = new(CreateFactory);

    public static ILoggerFactory LoggerFactory => LoggerFactoryInstance.Value;

    public static Microsoft.Extensions.Logging.ILogger CreateLogger<T>()
    {
        return LoggerFactory.CreateLogger<T>();
    }

    private static ILoggerFactory CreateFactory()
    {
        var serilogLogger = new LoggerConfiguration()
            .Enrich.FromLogContext()
            .WriteTo.Console()
            .CreateLogger();

        return Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
        {
            builder.ClearProviders();
            builder.AddSerilog(serilogLogger, dispose: true);
        });
    }
}
