【Net6】Net6使用Serilog的一个Program.cs 备份
主要代码从Serilog的Wiki里复制,调整为net6写法
https://github.com/serilog/serilog-aspnetcore#serilogaspnetcore---
dotnet add package Serilog.AspNetCore
using Serilog;
using Serilog.Events;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
try
{
Log.Information("Starting web host");
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
var app = builder.Build();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}