'where can i turn off request trace logs in app insights

I have app insights set up in my .net core app and in the logs I see these request traces:

Request starting HTTP/1.1 GET Request finished in 1.0838ms 404

These are being logged quite a bit and are pushing up the billing. How can I switch these off?



Solution 1:[1]

If you want to disable telemetry conditionally and dynamically, you can resolve the TelemetryConfiguration instance with an ASP.NET Core dependency injection container anywhere in your code and set the DisableTelemetry flag on it.

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddApplicationInsightsTelemetry();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, TelemetryConfiguration configuration)
    {
        configuration.DisableTelemetry = true;
        ...
    }

Result:

enter image description here

The preceding code sample prevents the sending of telemetry to Application Insights. It doesn't prevent any automatic collection modules from collecting telemetry. If you want to remove a particular auto collection module, see remove the telemetry module.

Solution 2:[2]

Quite likely these are coming from ILogger logs. You can use a filter to not collect ILogger logs based on category. You'll need to find the category and apply a filter, so that these logs don't get sent to ApplicationInsights.

The following completely disables ILogger logs from all category. You'd want something more custom, and you can adjust the filter accordingly.

builder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.None);

https://docs.microsoft.com/azure/azure-monitor/app/ilogger#create-filter-rules-in-configuration-with-appsettingsjson

Solution 3:[3]

I fixed this issue by applying the filter for ApplicationInsights in appsettings.json. This will log categories that start with "Microsoft.AspNetCore" at level "LogLevel.Warning" and higher only.

  "Logging": {
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information",`
        "Microsoft.AspNetCore": "Warning"
      }
    }
  },

See: https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger#create-filter-rules-in-configuration-with-appsettingsjson

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tupac
Solution 2 cijothomas
Solution 3 Yuby