Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering out Azure ServiceBus logs from WebJob Application Insights

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. enter image description here

like image 524
Kurt Camilleri Avatar asked Oct 27 '25 05:10

Kurt Camilleri


1 Answers

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.

like image 83
LudoGo Avatar answered Oct 29 '25 09:10

LudoGo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!