安福网站制作云南网站建设是什么
文章目录
- 项目地址
 - 一、Serilog使用
 - 1.1 安装 Serilog
 - 1.2 注册日志服务
 - 1.3 设置日志级别和详情
 - 1.4 配置到文件里
 - 1.5 给不同的环境配置日志
 - 1.5.1 配置appsettings.Development.json
 
- 二、Swagger的使用
 - 三、自定义Exception中间件
 - 3.1 使用FluentValidation
 
项目地址
- 教程作者:
 - 教程地址:
 
 
- 代码仓库地址:
 
 
- 所用到的框架和插件:
 
dbt 
airflow
 
一、Serilog使用
1.1 安装 Serilog
给Restaurants.API层安装Serilog
  <ItemGroup><PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets></PackageReference><PackageReference Include="Serilog.AspNetCore" Version="9.0.0" /></ItemGroup>
 
1.2 注册日志服务
注册日志服务到程序入口Program.cs
builder.Host.UseSerilog((context, configuration) =>configuration.MinimumLevel.Override("Microsoft", LogEventLevel.Warning).MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Information).WriteTo.Console()
);app.UseSerilogRequestLogging(); 
1.3 设置日志级别和详情
- 程序入口设置日志级别 ①程序级别是Warning;②EntityFrameworkCore显示Information;③ 配置日志显示内容
 
builder.Host.UseSerilog((context,configuration) =>configuration.MinimumLevel.Override("Microsoft",LogEventLevel.Warning).MinimumLevel.Override("Microsoft.EntityFrameworkCore",LogEventLevel.Information).WriteTo.Console(outputTemplate: "[{Timestamp:dd-MM HH:mm:ss} {Level:u3}] |{SourceContext}| {NewLine}{Message:lj}{NewLine}{Exception}")
);
 
- 在EFcore的配置文件设置日志显示
 
Restaurants.Infrastructure/Extensions/ServiceCollectionExtensions.cs

 3. 将需要显示的信息添加到各个Handler里
logger