Base solution for your next web application
Open Closed

Azure application insights ? #12194


User avatar
0
amontalvo created

Is there a way to send error logs to azure application insights?


1 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi amontalvo

    Install the Microsoft.ApplicationInsights.AspNetCore package in your project. Add the Instrumentation Key from your Azure Application Insights resource to the appsettings.json file. Application Insights by adding services.AddApplicationInsightsTelemetry() in the ConfigureServices method. Your existing ILogger setup will automatically send logs to Application Insights.

    Example:

    appsettings.json

    {
      "ApplicationInsights": {
        "InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
      }
    }
    

    Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        //...
        
        services.AddApplicationInsightsTelemetry(Configuration["ApplicationInsights:InstrumentationKey"]);
    
        //...
    }
    

    You can configure it this way if you only want to send error logs

    "Logging": {
        "ApplicationInsights": {
          "LogLevel": {
            "Default": "Error"
          }
        }
      },