我正在编写一个函数应用程序,它被删减到以下内容
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
“构造函数日志”应该写在哪里?
当调用_Constructorlog时,LogInformation是ILogger<TestProcessor>类型。
这是`hosts.json的文件
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}我还尝试使用来自https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0的各种JSON
发布于 2022-07-06 16:37:50
命名空间需要添加到类的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时,我需要测试这些设置是如何应用的,但是这在本地是可行的。
https://stackoverflow.com/questions/72882209
复制相似问题