Ok, it is still possible to set ApplicationInsights manually using ApplicationInsightsServiceOptions
. Here is the source code, how the settings are actually resolved:
internal static void AddTelemetryConfiguration(IConfiguration config, ApplicationInsightsServiceOptions serviceOptions)
{
string str1 = config["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (string.IsNullOrWhiteSpace(str1))
str1 = config["ApplicationInsights:InstrumentationKey"];
if (!string.IsNullOrWhiteSpace(str1))
serviceOptions.InstrumentationKey = str1;
string str2 = config["APPINSIGHTS_DEVELOPER_MODE"];
if (string.IsNullOrWhiteSpace(str2))
str2 = config["ApplicationInsights:TelemetryChannel:DeveloperMode"];
if (!string.IsNullOrWhiteSpace(str2))
{
bool result = false;
if (bool.TryParse(str2, out result))
serviceOptions.DeveloperMode = new bool?(result);
}
string str3 = config["APPINSIGHTS_ENDPOINTADDRESS"];
if (string.IsNullOrWhiteSpace(str3))
str3 = config["ApplicationInsights:TelemetryChannel:EndpointAddress"];
if (!string.IsNullOrWhiteSpace(str3))
serviceOptions.EndpointAddress = str3;
string str4 = config["version"];
if (string.IsNullOrWhiteSpace(str4))
return;
serviceOptions.ApplicationVersion = str4;
}
So you can see the highest priority have the Environment Variables. You can set the APPINSIGHTS_INSTRUMENTATIONKEY
variable in Azure Application settings and it will be picked up.
If the VS2017 Connected Services setup is used, it stores its configuration into csproj
, appsettings.json
(InstrumentationKey) and /Connected Services/Application Insights/ConnectedServices.json
.