我一直在尝试过滤掉我的 ServiceBus 触发的 webjob 在 Application Insights 中发送的信息消息。这些消息由以下两个日志组成:
ReceiveBatchAsync start. MessageCount = 1
ReceiveBatchAsync done. Received '0' messages. LockTokens =
我的目标是仅记录我在代码中记录的信息跟踪,并忽略来自 Azure.Messaging.ServiceBus 的日志。我怎样才能实现这个目标?
<小时/>到目前为止,我已尝试在我的program.cs文件中使用以下代码添加过滤器
b.AddFilter("Azure.Messaging.ServiceBus", LogLevel.Warning);
我还尝试在我的 appsettings.json 文件中添加以下设置
"Logging": {
"LogLevel": {
"Default": "Information",
"Azure.Messaging.ServiceBus": "Warning"
}
},
<小时/>
就我的设置而言,我正在使用以下值得关注的软件包:
- Microsoft.Extensions.Logging.Console
- Microsoft.Azure.WebJobs.Extensions.ServiceBus
最佳答案
我在过滤某些服务总线或 EFCore 日志时遇到了同样的问题。 我能够部分解决这个问题,在日志配置代码中添加一些硬编码的过滤器:
builder.ConfigureLogging((context, b) => {
// If the key exists in settings, use it to enable Application Insights.
string instrumentationKey = context.Configuration["EASY_APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(instrumentationKey)) {
b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = instrumentationKey);
}
b.AddConsole();
b.AddFilter("Azure.Messaging.ServiceBus", LogLevel.Error);
b.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Error);
});
但我想知道如何在从 AppService 设置更新设置时设置日志记录。
关于azure - 从 WebJob Application Insights 中筛选出 Azure ServiceBus 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72963764/