我有一个用 .Net 8 编写的简单
dotnet-isolated
Azure 函数,它有 1 个 Http 触发函数。我有另一个自定义数据库记录器,它被添加到此函数中以启用数据库日志记录。
当我执行该函数时,没有任何与 Microsoft 相关的日志记录被过滤,并且它在我的数据库中记录了数百个条目。我已经使用一个简单的控制台应用程序测试了我的自定义记录器,其中日志记录过滤工作正常。有趣的是除了我自己的自定义记录器之外,控制台日志也没有被过滤。
这就是我的
Program.cs
的样子:-
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureAppConfiguration((context, builder) =>
{
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("local.settings.json", optional: true);
})
.ConfigureLogging((builder, logging) =>
{
logging.AddConsole();
logging.AddDbLogger(options =>
{
builder.Configuration.GetSection("Database")
.GetSection("Options").Bind(options);
});
})
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
我已经添加了相应的内容。登录
host.json
文件:-
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
},
"logLevel": {
"default": "Information",
"Microsoft": "Error"
},
"Database": {
"logLevel": {
"default": "Error"
}
},
"console": {
"logLevel": {
"default": "Error"
}
}
}
}
它仍然显示
Console
和数据库中的日志条目。
我的
host.json
有什么问题吗?
builder.Configuration.GetSection("Database").GetSection("Options").Bind(options);});
^^ 这不应该是
builder.Configuration.GetSection("Database").Bind(options);});
?
无法识别
.GetSection("Options")
或它所指的内容。