2017-05-12 41 views
0

之前的VS2017,可以將代碼中的Application Insight集成到Asp.NET核心應用程序中。在VS2017中,只有使用IDE(連接服務)作爲「Microsoft.ApplicationInsights.AspNetCore」(2.0.0。)不再提供​​擴展。所有相關資源不適用於VS2017(即https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started)。VS.2017中的Asp.Net核心和應用程序洞察 - 多種環境

當使用新的VS2017功能「連接服務」時,我們應該如何連接到不同的應用程序見解實例?

回答

1

好的,仍然可以使用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中。

+0

AddInslemetryConfiguration方法可以在ApplicationInsightsExtensions類中找到。 –

相關問題