伊洛格写信给哪里<TCategoryName>?



我正在写一个函数应用程序,它修剪到这个

namespace myNamespace {
public class Test {
private readonly ILogger _Constructorlog;
public Test(ILogger<TestProcessor> logger) {
_Constructorlog = logger;
}
[FunctionName("TestLog")]
public async Task<IActionResult> RunWeb([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger methodLog) {
methodLog.LogInformation("method log");
_Constructorlog.LogInformation("Constructor log");
}
}
}

这段代码按照预期将这个写入控制台窗口

[2022-07-06T10:07:35.302Z] method log

Where should "Constructor log"会写吗?

调用LogInformation时,_Constructorlog类型为ILogger<TestProcessor>

这是"主机"。json文件的

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}

我也试着用各种JSONhttps://learn.microsoft.com/en us/aspnet/core/fundamentals/logging/?view=aspnetcore - 6.0

需要将命名空间添加到类的host.json

"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"default": "None",
"myNamespace": "Information"
}
}
}

None在这里停止依赖注入ILogger.LogInformation显示在控制台窗口,所以method log不写入。

Information添加到这里的命名空间意味着该命名空间的ILogger<TCategoryName>.LogInformation将写入控制台窗口。

删除"default": "None",将两者都写入控制台窗口。

我需要测试这些设置上传到Azure时如何应用,但这在本地工作。