【问题标题】:Filtering out Azure ServiceBus logs from WebJob Application InsightsFiltering out Azure ServiceBus logs from WebJob Application Insights
【发布时间】:2022-12-02 07:21:18
【问题描述】:

I have been trying to filter out information messages that my ServiceBus triggered webjob is sending in the Application Insights. These messages consist of these two logs:

ReceiveBatchAsync start. MessageCount = 1
ReceiveBatchAsync done. Received '0' messages. LockTokens =

My goal is to only log information traces that I am logging in my code and ignore the logs coming from Azure.Messaging.ServiceBus. How can I achieve this?


So far I have tried to add a filter using the following code in my program.cs file

b.AddFilter("Azure.Messaging.ServiceBus", LogLevel.Warning);

and I have also tried to add the following settings in my appsettings.json file

"Logging": {
    "LogLevel": {
        "Default": "Information",
        "Azure.Messaging.ServiceBus": "Warning"
    }
},

As for my set up I am using the following packages which are of concern:

  • Microsoft.Extensions.Logging.Console
  • Microsoft.Azure.WebJobs.Extensions.ServiceBus

The following code is my Logging configuration in the program.cs file.

【问题讨论】:

  • I have the exact same problem. Were you ever able to solve it?
  • I was not able to solve it so far. I believe there is a workaround by implementing Serilog (I have not tested if Serilog works), but I wish to solve it without including other third-party packages.

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


【解决方案1】:

I had the same issue to filter some Service Bus or EFCore logs. I was able to partially solve this adding some hardcoded filter into the logging configuration code :

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);

});

But i would like to know how can i setup logging just in updating settings from AppService's settings.

【讨论】:

  • I tried to add setting into appsettings.json, into AppService Setting like { "name": "Logging:LogLevel:Default", "value": "Warning", "slotSetting": false }, but this does not work at all !
猜你喜欢
  • 2022-12-19
  • 2019-07-05
  • 1970-01-01
  • 2017-06-13
  • 1970-01-01
  • 1970-01-01
  • 2022-01-11
  • 2021-07-16
  • 2016-12-09
相关资源
最近更新 更多