Search code examples
azureasp.net-coreazure-application-insights

How to make Application Insights stop logging "AspNetCoreEnvironment: Production"?


Application Insights SDK for asp.net core is always inserting a custom dimension called "AspNetCoreEnvironment" with the value "Production" on my requests, dependencies, traces and etc...

How can I disable this?


Solution

  • Whenever we configure Application Insights for a WebApp, by default AspNetCoreEnvironment can be seen under Custom properties of a Request,Custom Event and even on Trace Logs.

    enter image description here

    In Program.cs file, after

    builder.Services.AddApplicationInsightsTelemetry(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]);
    

    I have added the below line of code.

    builder.Services.RemoveAll<ITelemetryInitializer>();
    

    Now I can see that the AspNetCoreEnvironment property is excluded from the logs.

    Request: enter image description here

    Custom Event and Trace:

    enter image description here