You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Azure App Service App setting for Application Insights Instrumentation key, but it's not being picked up.
Cause
I mistakenly removed .AddEnvironmentVariables() which is important for Azure App settings, without it those settings will not be picked up, see this commit d249584#commitcomment-25810929
Fix
I updated the code in Program.cs to debug
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables() // <-- important
.AddCommandLine(args)
.Build();
var instrumentKey = configuration.GetValue<string>("ApplicationInsights:InstrumentationKey");
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
.WriteTo.ApplicationInsightsTraces(instrumentKey)
.CreateLogger();
Log.Warning("Instrumentation Key: " + instrumentKey);
Things Learned
The key in Azure App settings can be either ApplicationInsights:InstrumentationKey or ApplicationInsights__InstrumentationKey.
ASPNETCORE_ENVIRONMENT on Azure seems to be not existed, so I default in my code for it to be "Production".
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.cs.json")
.AddJsonFile($"appsettings.cs.{env.EnvironmentName}.json", optional: true);
Therefore here, the default value will be production.
The text was updated successfully, but these errors were encountered:
Issue
I have a Azure App Service App setting for Application Insights Instrumentation key, but it's not being picked up.
Cause
I mistakenly removed .AddEnvironmentVariables() which is important for Azure App settings, without it those settings will not be picked up, see this commit d249584#commitcomment-25810929
Fix
I updated the code in Program.cs to debug
Things Learned
The key in Azure App settings can be either ApplicationInsights:InstrumentationKey or ApplicationInsights__InstrumentationKey.
ASPNETCORE_ENVIRONMENT on Azure seems to be not existed, so I default in my code for it to be "Production".
The hosting environment default value is "production", see
aspnet/Hosting#863
https://github.com/aspnet/Hosting/blob/b6da89f54cff11474f17486cdc55c2f21f2bbd6b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironment.cs#L10
Therefore here, the default value will be production.
The text was updated successfully, but these errors were encountered: