DEV Community

Cover image for How to configure Azure Applications Insights on .Net 5
Rafael Ahrons
Rafael Ahrons

Posted on • Originally published at luturol.github.io

2 2

How to configure Azure Applications Insights on .Net 5

How to configure Azure Applications Insights on .Net 5

Application insights is a wonderful tool to help you track log, see performance issues and application map. It's more like CloudWatch on AWS.

First, you need to download two packages from nuget to start.

  1. Microsoft.ApplicationInsights.AspNetCore

  2. Microsoft.Extensions.Logging.ApplicationInsights

dotnet add package Microsoft.ApplicationInsights.AspNetCore --version 2.17.0
dotnet add package Microsoft.Extensions.Logging.ApplicationInsights --version 2.17.0
Enter fullscreen mode Exit fullscreen mode

After that, you need to initialize the configurations from application insights on Statup.cs and Program.cs

On Startup.cs, you need to add the service dependency.

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry();

    //others dependencies
}
Enter fullscreen mode Exit fullscreen mode

On Program.cs, you need to set the Log Level and your Instrumentation Key.

public static IHostBuilder CreateHosBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureLogging(logging =>
        {
            logging.AddApplicationInsights("your-instrumentation-key");
            logging.AddFilter<ApplicationINsightsLoggerProvider>("", LogLevel.Trace);
        })
        .ConfigureWebHostDefaults(webBuilder => 
        {
            webBuilder.UseStartup<Startup>();
        });
Enter fullscreen mode Exit fullscreen mode

Now you can use ILogger to create logs on Azure Application Insights.

Don't forget to eat clean and drink water.

Peace!!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay