1)安装nuget包
Install-Package Serilog.Settings.Configuration
2)修改Startup的代码
Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .WriteTo.RollingFile(Path.GetFullPath("logs/log-{Date}.txt")) .CreateLogger();
3)在appsettings.json中添加配置
"Serilog": { "MinimumLevel": { "Default": "Error", "Override": { "System": "Warning", "Microsoft": "Warning", "Cnblogs": "Debug" } } }
Install-Package Serilog.Settings.AppSettings
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
... // Other configuration here, then
.CreateLogger()
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="serilog:minimum-level" value="Verbose" />
<!-- More settings here -->
官方文档里有说明:
https://github.com/serilog/serilog/wiki/AppSettings
这个是web.config的配置