Skip to content

ApplicationInsights

Mohammad Moattar edited this page Dec 4, 2020 · 3 revisions

To be able to use the telemetry using ApplicationInsights, install the following package from the NuGet

dotnet add package Easify.Azure.AspNetCore.AppInsights

The following section for ApplicationInsights need to be added to appsettings.json

  "ApplicationInsights": {
    "InstrumentationKey": "Instrument Key Here"
  },

And finally, in the startup, the following extension will activate

services.AddTelemetry();

By default, it configures the ApplicationInsights and register the component with Application Name (Coming from the Application section of the configuration), and publish tracing and telemetry information there. It also enables the SQL server trace when the telemetry involves the connection to SQL Server.

Disabling SQL Tracing

The configure optional parameter can be used to disable the SQL tracing. Here is an example:

services.AddTelemetry(options => 
{
    options.DisableSqlInstrumentation();
});

Extensions

AddTelemetry extension method registers Application Insights with the default configurations but it can take a delegate as a parameter which allows on making further configuration changes.

services.AddTelemetry(options => 
{
    // Make changes to options here
});
Clone this wiki locally