[英]asp.net framework 4.7 configure logging level, not working
My web job is not adhering to the logging level configuration in my host.json.我的 Web 作业不符合我的 host.json 中的日志记录级别配置。 It is written using .NET framework 4.7.
它是使用 .NET 框架 4.7 编写的。 The expected result with the below code is no logging, instead, I get logging a per the below screenshot.
下面代码的预期结果是没有日志记录,相反,我根据下面的屏幕截图记录了一个。 Can any provide guidance on how to fix this?
任何人都可以提供有关如何解决此问题的指导吗? Do I need to add additional configuration/startup code?
我需要添加额外的配置/启动代码吗?
host.json主机文件
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"Functions.Test": "None",
"default": "None"
}
}
}
C# Web Job Code C# Web 作业代码
public static void Main()
{
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("host.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddTimers();
b.AddBuiltInBindings();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
var host = builder.Build();
using (host)
{
var jobHost = host.Services.GetService(typeof(IJobHost)) as JobHost;
jobHost.CallAsync("Test").GetAwaiter().GetResult();
}
}
}
public class Functions
{
[NoAutomaticTrigger]
public static void Test(ILogger logger)
{
logger.LogCritical("LogCritical");
logger.LogDebug("LogDebug");
logger.LogError("LogError");
logger.LogInformation("LogInformation");
logger.LogTrace("LogTrace");
logger.LogWarning("LogWarning");
Thread.Sleep(1000 * 10);
}
}
}
thanks for sharing your code.感谢您分享您的代码。
It seems to me that in the first statement a config object is being built var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()...
, however, later in the code this config
variable is not used while host creation and configuration.在我看来,在第一条语句中,正在构建配置对象
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()...
,但是,在代码的后面,在主机创建和配置时不使用此config
变量。 As a result, those settings are not applied and default Information
logLevel is used.因此,不会应用这些设置,而是使用默认的
Information
logLevel。
We need to supply this configuration to the HostBuilder
, looks like it can be done using HostBuilder
's ConfigureAppConfiguration
method.我们需要将此配置提供给
HostBuilder
,看起来可以使用HostBuilder
的ConfigureAppConfiguration
方法来完成。 Please take a look at this question , it has an example how to use this method.请看一下这个问题,它有一个如何使用这种方法的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.