3

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

  • I have the exact same problem. Were you ever able to solve it? – sac80644 Sep 20 '22 at 01:58
  • 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. – Kurt Camilleri Sep 26 '22 at 08:20

1 Answers1

0

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.

Alessandro Benassi
  • 1,640
  • 2
  • 14
  • 19
LudoGo
  • 21
  • 3
  • 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 ! – LudoGo Nov 18 '22 at 09:11