perf: 优化启动配置
parent
0f6893d174
commit
3ff1c8620c
@ -1,42 +1,50 @@
|
||||
|
||||
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();
|
||||
|
||||
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/all/log-.txt", rollingInterval: RollingInterval.Day,
|
||||
restrictedToMinimumLevel: LogEventLevel.Debug))
|
||||
.WriteTo.Async(c => c.File("logs/error/error-.txt", rollingInterval: RollingInterval.Day,
|
||||
restrictedToMinimumLevel: LogEventLevel.Error))
|
||||
.WriteTo.Async(c => c.Console())
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
Log.Information("""
|
||||
_ _____ _ ____ __
|
||||
/ |/ / _ \(_)__ / __/______ ___ _ ___ _ _____ ____/ /__
|
||||
/ / ___/ / _ \/ _// __/ _ `/ ' \/ -_) |/|/ / _ \/ __/ '_/
|
||||
/_/|_/_/ /_/_//_/_/ /_/ \_,_/_/_/_/\__/|__,__/\___/_/ /_/\_\
|
||||
""");
|
||||
Log.Information("NPin-Framework (Abp.vNext) 启动!");
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
Log.Information($"当前主机启动环境-【{builder.Environment.EnvironmentName}】");
|
||||
Log.Information($"当前主机启动地址-【{builder.Configuration["App:SelfUrl"]}】");
|
||||
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();
|
||||
}
|
Loading…
Reference in New Issue