我试图使用预发行的NuGet包Serilog.Settings.Configuration
从appsettings.json中加载Serilog配置。但是,当我使用Configuration.GetSection进行加载时,该值仍然返回null。
以下是我在Program.cs文件中的代码:
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(
(hostingContext, loggingBuilder) =>
{
loggingBuilder.ClearProviders();
loggingBuilder.AddSerilog(
new LoggerConfiguration()
.ReadFrom.ConfigurationSection(hostingContext.Configuration.GetSection("Serilog"))
.CreateLogger()
);
}
);
这是我在appsettings.json文件中的内容:
{
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Verbose",
"System": "Verbose",
"Microsoft.AspNetCore.Authentication": "Verbose"
}
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "*my_connectionString*",
"tableName": "ErrorLog"
}
}
]
}}
已安装的NuGet包:
- Microsoft.AspNetCore.App v2.1.1
- Serilog v2.7.1
- Serilog.AspNetCore v2.1.1
- Serilog.Extensions.Logging v2.0.2
- Serilog.Settings.Configuration v3.0.0-dev-00119
- Serilog.Sinks.MSSqlServer v5.1.2