From 3ff1c8620c6cb73bb4068ac7af95adea50d792c7 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Mon, 6 May 2024 15:01:01 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/NPin.Web/Program.cs | 90 ++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/src/NPin.Web/Program.cs b/src/NPin.Web/Program.cs index d1134c4..de118f8 100644 --- a/src/NPin.Web/Program.cs +++ b/src/NPin.Web/Program.cs @@ -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(); - 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(); + var app = builder.Build(); + await app.InitializeApplicationAsync(); + await app.RunAsync(); +} +catch (Exception ex) +{ + Log.Fatal(ex, "NPin-Framework (Abp.vNext) 爆炸!"); +} +finally +{ + Log.CloseAndFlush(); } \ No newline at end of file