我试图使用Serilog.Settings.Configuration
预发布NuGet包从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包: