好的,仍然可以使用ApplicationInsightsServiceOptions
手動設置ApplicationInsights。這裏是源代碼,設置如何實際解決:
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;
}
所以你可以看到最高優先級的環境變量。您可以在Azure應用程序設置中設置APPINSIGHTS_INSTRUMENTATIONKEY
變量,它將被拾取。
如果使用VS2017連接服務設置,它將其配置存儲在csproj
,appsettings.json
(InstrumentationKey)和/Connected Services/Application Insights/ConnectedServices.json
中。
AddInslemetryConfiguration方法可以在ApplicationInsightsExtensions類中找到。 –