
using NPin;
using Serilog;
using Serilog.Events;

// 创建日志
Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
    .MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
    .MinimumLevel.Override("Quartz", LogEventLevel.Warning)
    // 可使用{SourceContext}记录
    .Enrich.FromLogContext()
    .WriteTo.Async(c => c.File("logs/log-.txt", rollingInterval: RollingInterval.Day,
        restrictedToMinimumLevel: LogEventLevel.Debug))
    .WriteTo.Async(c => c.File("logs/error-.txt", rollingInterval: RollingInterval.Day,
        restrictedToMinimumLevel: LogEventLevel.Error))
    .WriteTo.Async(c => c.Console())
    .CreateLogger();

try
{
    Log.Information("NPin-Framework (Abp.vNext) 启动！");

    var builder = WebApplication.CreateBuilder(args);
    builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]);
    builder.Host.UseAutofac();
    builder.Host.UseSerilog();

    await builder.Services.AddApplicationAsync<NPinWebModule>();
    var app = builder.Build();
    await app.InitializeApplicationAsync();
    await app.RunAsync();
}
catch (Exception ex)
{
    Log.Fatal(ex, "NPin-Framework (Abp.vNext) 爆炸！");
}
finally
{
    Log.CloseAndFlush();
}