ApplicationInsights-dotnet
ApplicationInsights-dotnet copied to clipboard
console app application insight logging is not working
since Application Insights “Instrumentation Keys” are Sunsetting on March 31, 2025, i am trying to convert current applicationInsights config from Instrumentation Key to Connection String
current startup:
public void ConfigureServices(IServiceCollection services) => services .AddApplicationInsightsTelemetryWorkerService("00000000-0000-0000-0000-000000000000");
changed to
public void ConfigureServices(IServiceCollection services) => services .AddApplicationInsightsTelemetryWorkerService(options => options.ConnectionString = "InstrumentationKey="00000000-0000-0000-0000-000000000000");
but the new code is not logging anything to the same AI transaction logging. am I missing anything? thanks!
Make sure you copy the ConnectionString verbatim from your Application Insights resource. If that's not working, you can collect SDK logs to identify any errors within the SDK
thank you @TimothyMothra getting back to me here is my AI
the connection string is very long, shall i copy the whole thing or just InstrumentationKey=xxx part? and also where i can find the SDK logs? thank you!
Yes, full string. The SDK needs those Endpoint values.
Self diagnostics would be the easiest way to collect internal logs: https://github.com/microsoft/ApplicationInsights-dotnet/tree/main/troubleshooting/ETW#self-diagnostics
working with the InstrumentationKey is depricated.
You should work with the connectionstring
InstrumentationKey=xxx;IngestionEndpoint=xxx;LiveEndpoint=xxx;ApplicationId=xxx
https://learn.microsoft.com/en-us/azure/azure-monitor/app/connection-strings
On March 31, 2025, support for instrumentation key ingestion will end. Instrumentation key ingestion will continue to work, but we'll no longer provide updates or support for the feature. Transition to connection strings to take advantage of new capabilities.
services.AddApplicationInsightsTelemetryWorkerService(options =>
{
// default is EnvironmentVariable "APPLICATIONINSIGHTS_CONNECTION_STRING"
// so we overwrite with the appsettings
options.ConnectionString = configuration.GetValue<string>("ApplicationInsights:ConnectionString");
});