perf: 优化启动配置

main
NoahLan 8 months ago
parent 0f6893d174
commit 3ff1c8620c

@ -1,42 +1,50 @@
using NPin; using NPin;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
// 创建日志 // 创建日志
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug() .MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error) .MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
.MinimumLevel.Override("Quartz", LogEventLevel.Warning) .MinimumLevel.Override("Quartz", LogEventLevel.Warning)
// 可使用{SourceContext}记录 // 可使用{SourceContext}记录
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Async(c => c.File("logs/log-.txt", rollingInterval: RollingInterval.Day, .WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: LogEventLevel.Debug)) restrictedToMinimumLevel: LogEventLevel.Debug))
.WriteTo.Async(c => c.File("logs/error-.txt", rollingInterval: RollingInterval.Day, .WriteTo.Async(c => c.File("logs/error/error-.txt", rollingInterval: RollingInterval.Day,
restrictedToMinimumLevel: LogEventLevel.Error)) restrictedToMinimumLevel: LogEventLevel.Error))
.WriteTo.Async(c => c.Console()) .WriteTo.Async(c => c.Console())
.CreateLogger(); .CreateLogger();
try try
{ {
Log.Information("NPin-Framework (Abp.vNext) 启动!"); Log.Information("""
_ _____ _ ____ __
var builder = WebApplication.CreateBuilder(args); / |/ / _ \(_)__ / __/______ ___ _ ___ _ _____ ____/ /__
builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]); / / ___/ / _ \/ _// __/ _ `/ ' \/ -_) |/|/ / _ \/ __/ '_/
builder.Host.UseAutofac(); /_/|_/_/ /_/_//_/_/ /_/ \_,_/_/_/_/\__/|__,__/\___/_/ /_/\_\
builder.Host.UseSerilog(); """);
Log.Information("NPin-Framework (Abp.vNext) 启动!");
await builder.Services.AddApplicationAsync<NPinWebModule>();
var app = builder.Build(); var builder = WebApplication.CreateBuilder(args);
await app.InitializeApplicationAsync(); Log.Information($"当前主机启动环境-【{builder.Environment.EnvironmentName}】");
await app.RunAsync(); Log.Information($"当前主机启动地址-【{builder.Configuration["App:SelfUrl"]}】");
} builder.WebHost.UseUrls(builder.Configuration["App:SelfUrl"]);
catch (Exception ex) builder.Host.UseAutofac();
{ builder.Host.UseSerilog();
Log.Fatal(ex, "NPin-Framework (Abp.vNext) 爆炸!");
} await builder.Services.AddApplicationAsync<NPinWebModule>();
finally var app = builder.Build();
{ await app.InitializeApplicationAsync();
Log.CloseAndFlush(); await app.RunAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "NPin-Framework (Abp.vNext) 爆炸!");
}
finally
{
Log.CloseAndFlush();
} }
Loading…
Cancel
Save