using Microsoft.Extensions.Configuration;
using Serilog.Events;
using Serilog;
using Serilog.Extensions.Hosting;

namespace YTExtractor.Logging.Configuration
{
    public static class SerilogConfiguration
    {
        public static LoggerConfiguration SetLoggerConfiguration(this WebApplicationBuilder builder, LoggerConfiguration config, IServiceProvider services, IConfiguration configuration)
        {
            var workspace = configuration["Serilog:Properties:Workspace"];
            var seqServer = configuration.GetValue<string>("Serilog:WriteTo:2:Args:serverUrl"); ;

            config
                .ReadFrom.Configuration(configuration)
                .ReadFrom.Services(services)
                .Enrich.FromLogContext()
                .Enrich.WithEnvironmentName()
                //.Enrich.WithMachineName()
                .Enrich.WithProperty("Application", "SumaTube")
                .Enrich.WithProperty("Workspace", workspace)
                .WriteTo.Seq(seqServer)
                ;

            return config;
        }

    }
}
