mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
- 统一 Serilog 文件与控制台日志的输出模板,提升可读性 - 降低部分 ASP.NET Core 内部组件的日志级别,减少无关噪音 - 移除前端 types 中未使用的 ElSegmented 组件声明
56 lines
2.7 KiB
C#
56 lines
2.7 KiB
C#
using System.Text.Json;
|
||
using Serilog;
|
||
using Serilog.Events;
|
||
using Yi.Abp.Web;
|
||
|
||
//创建日志,可使用{SourceContext}记录
|
||
var outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}【{SourceContext}】[{Level:u3}]{Message:lj}{NewLine}{Exception}";
|
||
Log.Logger = new LoggerConfiguration()
|
||
//由于后端处理请求中,前端请求已经结束,此类日志可不记录
|
||
.Filter.ByExcluding(log =>log.Exception?.GetType() == typeof(TaskCanceledException)||log.MessageTemplate.Text.Contains("\"message\": \"A task was canceled.\""))
|
||
.MinimumLevel.Debug()
|
||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Diagnostics", LogEventLevel.Error)
|
||
.MinimumLevel.Override("Quartz", LogEventLevel.Warning)
|
||
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", LogEventLevel.Warning)
|
||
.MinimumLevel.Override("Microsoft.AspNetCore.Cors.Infrastructure.CorsService", LogEventLevel.Warning)
|
||
.MinimumLevel.Override("Microsoft.AspNetCore.Authorization.DefaultAuthorizationService", LogEventLevel.Warning)
|
||
.Enrich.FromLogContext()
|
||
.WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Debug,outputTemplate:outputTemplate))
|
||
.WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error,outputTemplate:outputTemplate))
|
||
.WriteTo.Async(c => c.Console(outputTemplate:outputTemplate))
|
||
.CreateLogger();
|
||
|
||
try
|
||
{
|
||
Log.Information("""
|
||
|
||
__ ___ ______ _
|
||
\ \ / (_) | ____| | |
|
||
\ \_/ / _ | |__ _ __ __ _ _ __ ___ _____ _____ _ __| | __
|
||
\ / | | | __| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
|
||
| | | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
|
||
|_| |_| |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\
|
||
|
||
""");
|
||
Log.Information("Yi框架-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<YiAbpWebModule>();
|
||
var app = builder.Build();
|
||
await app.InitializeApplicationAsync();
|
||
await app.RunAsync();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Fatal(ex, "Yi框架-Abp.vNext,爆炸!");
|
||
}
|
||
finally
|
||
{
|
||
Log.CloseAndFlush();
|
||
} |