How to remove Informational traces from Azure.Core category

Haralambie Baciu 0 Reputation points
2023-12-07T13:23:12.0233333+00:00

I have a .net 7 web api with some webjobs which are using some packages from Azure.Core. During execution some system logs under Azure.Core are displayed in ApplicationInsights resource. I get too many traces with this message:

Trace example: Severity level: Information, Message: Request [specific GUID].

The only logs that I want to be displayed in application insights are the ones starting from Warning level. I did this in appsettings configuration file but it seems that is not working properly. I attached lower the config file for Logging.

 "Logging": {
     "IncludeScopes": false,
     "LogLevel": {
         "Default": "Debug",
         "Microsoft": "Warning",
         "System": "Information",
         "Azure.Identity": "Warning",
         "Azure.Core": "Warning"
     }
 },
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,939 questions
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,731 Reputation points Microsoft Employee Moderator
    2023-12-09T01:18:18.3566667+00:00

    @Haralambie Baciu It seems like you have already set the log level for the "Azure.Core" category to "Warning" in your appsettings.json file. However, you are still seeing logs with severity level "Information" from the "Azure.Core" category in Application Insights.

    One possible reason for this could be that the log level for the "Azure.Core" category is being overridden somewhere else in your code. To ensure that the log level is set to "Warning" for the "Azure.Core" category throughout your application, you can add the following code in your Program.cs file:

    using Microsoft.Extensions.Logging;
    
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddConsole();
                logging.AddAzureWebAppDiagnostics();
                logging.AddFilter("Azure.Core", LogLevel.Warning);
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup();
            });
    
    
    

    This code clears all the existing logging providers, adds the console logging provider, adds the Azure Web App Diagnostics logging provider, and sets the log level for the "Azure.Core" category to "Warning".

    Please note that this code assumes that you are using the default host builder in your application. If you have a custom host builder, you can modify the code accordingly.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.