'How can I filter ASP.NET Core in Application Insights from our startup app

I would like to filter anything in the following category in our application insights:

  • "Microsoft.AspNetCore.Hosting.Diagnostics"
  • "Microsoft.AspNetCore.Routing.EndpointMiddleware"
  • "Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker"
  • "Microsoft.EntityFrameworkCore.Infrastructure"

I have added the following in our startup app and the only one I could filter is the EF ones but I still see the Microsoft.AspNetCore entries:

services.AddApplicationInsights(GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY"),
                GetEnvironmentVariable("CloudRoleName"),
                MicroserviceName,
                ComponentName);
services.Configure<LoggerFilterOptions>(x => x.AddFilter("Microsoft.EntityFrameworkCore", GetEnvironmentVariable("MinimumLogLevel").GetLogLevel()));
services.Configure<LoggerFilterOptions>(x => x.AddFilter("Microsoft.AspNetCore", GetEnvironmentVariable("MinimumLogLevel").GetLogLevel()));   

This is what I want to filter:

enter image description here

Any thoughts please?



Solution 1:[1]

You can try below code:

services.AddApplicationInsightsTelemetry();
services.AddLogging(options =>
{                
    options.AddFilter("AspNetCoreEnvironment", LogLevel.Trace);
    options.AddFilter("Microsoft.AspNetCore", LogLevel.Critical);
    options.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Critical);
});

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 Jason