azure - 从 WebJob Application Insights 中筛选出 Azure ServiceBus 日志

标签 azure azure-application-insights azureservicebus azure-webjobs log-level

我一直在尝试过滤掉我的 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

以下代码是我在program.cs文件中的日志记录配置。 enter image description here

最佳答案

我在过滤某些服务总线或 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/

相关文章:

linux -/etc/sudoers 文件有问题但无法访问 root

c# - 中国地区应用洞察

angularjs - "https://dc.services.visualstudio.com/v2/track"有什么用

c# - .Net 中的 key 锁

python - 导入错误: cannot import name 'ServiceBusClient' from 'azure.servicebus'

sql-server - Microsoft Codename "Data Transfer"标识列错误

azure - 使用托管标识和 REST API 从 VM 调用 Azure 函数

azure - Slack 消息不会到达 Azure

azure - 什么是 LoggerExtension Args 参数以及如何与应用程序见解集成?

azure - 在 Azure 服务总线订阅上配置共享访问签名