I am trying to set the InstrumentationKey of AppInsights TTelemetry from appsettings.json. My code looks like this
Program.cs
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
});
Startup.cs, ConfigureServices()
services.AddApplicationInsightsTelemetry(Configuration);
appsettings.json
"ApplicationInsights": {
"InstrumentationKey": "[my key]"
},
However, when I run _serviceProvider.GetService(), or recieved the TelemetryClient via dependecy injection in the controller, the telemetry.Context.InstrumentationKey is empty.