Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Last active February 14, 2026 16:08
Show Gist options
  • Select an option

  • Save wullemsb/397789904fc04d0e5f1986719c7a6860 to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/397789904fc04d0e5f1986719c7a6860 to your computer and use it in GitHub Desktop.

Modify code

Make these necessary changes to the app.

  • Install client library
dotnet add package Microsoft.ApplicationInsights.WorkerService
  • Configure the app to use Azure Monitor An .NET Core Worker app typically has a Program.cs file that "builds" the app. Find this file and apply these changes.
    • Add the following usings at the top:
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
  • Before calling builder.Build(), add these lines:
 builder.Services.AddApplicationInsightsTelemetryWorkerService();
 builder.Services.ConfigureOpenTelemetryTracerProvider(t => {
    t.AddAspNetCoreInstrumentation()
     .AddHttpClientInstrumentation()
     .AddSqlClientInstrumentation()
     .AddSource("MassTransit");
});

- If Serilog is used in the app, install the following client library:

dotnet add package Serilog.Sinks.ApplicationInsights


Add the following using at the top:
```csharp
using Serilog.Sinks.ApplicationInsights;

And add Application Insights as a sink to Serilog configuration:

 .WriteTo.ApplicationInsights(TelemetryConverter.Traces,LogEventLevel.Information)

Configure App Insights connection string

The App Insights resource has a connection string. Add the connection string to the appsettings.json file. You can use Azure CLI to query the connection string of the App Insights resource. See scripts/appinsights.ps1 for what Azure CLI command to execute for querying the connection string.

After getting the connection string, add it to the appsettings.json file with its value.

  "ApplicationInsights": {
    "ConnectionString":"{your_application_insights_connection_string}"
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment