[英]How to read logging configuration from appsettings.json in .net Core 2.2
In .net Core 2.1 it was done like this 在.net Core 2.1中,它是这样完成的
var loggingConfig = configuration.GetSection("Logging");
loggerFactory.AddConsole(loggingConfig);
I have moved it to ConfigureServices and now I get 我已经将其移动到ConfigureServices,现在我得到了
Error CS1503 Argument 2: cannot convert from 'Microsoft.Extensions.Configuration.IConfigurationSection' to 'System.Action Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions'
错误CS1503参数2:无法从“ Microsoft.Extensions.Configuration.IConfigurationSection”转换为“ System.Action Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions”
Base on this you may have to change the way you are configuring your application: 基于此,您可能必须更改配置应用程序的方式:
var webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json",
optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
})
.UseStartup<Startup>()
.Build();
webHost.Run();
1 Microsoft ASP.NET Core 2.2 Logging documentation 1个 Microsoft ASP.NET Core 2.2记录文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.