Bill
Bill

Reputation: 183

Adding Configuration to Application Insights

So I recently installed Application Insights to my project through Visual Studio and it says that it is 100% configured, but there is no added code in my Startup.cs. Do I need to add anything to get it fully functional or is that it?

Upvotes: 2

Views: 1129

Answers (1)

meziantou
meziantou

Reputation: 21337

There are 2 ways to add application insights to an ASP.NET Core site.

In the Program.cs file:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .UseApplicationInsights() // Here
        .Build();

    host.Run();
}

Or in the ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration); // here
    var builder = services.AddMvc();
}

You need to add the instrumentation key in the appsettings.json file:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information"
    }
  },
  "ApplicationInsights": {
    "InstrumentationKey": "4bbb7b98-78f8-49c3-8ede-da3215b75f43"
  }
}

Upvotes: 1

Related Questions