2017-05-12 1 views
0

이전의 VS2017에서는 Application Insight 통합을 Asp.NET Core 응용 프로그램에 코드로 설정하는 것이 가능했습니다. VS2017에서는 "Microsoft.ApplicationInsights.AspNetCore"(2.0.0.)가 더 이상 builder.AddApplicationInsightsSettings(developerMode: true); 확장을 제공하지 않으므로 IDE (연결 서비스) 만 사용할 수 있습니다. VS2017 (예 : https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started)에 관련된 모든 리소스가 작동하지 않습니다.VS2017의 Asp.Net 핵심 및 응용 프로그램 통찰력 - 여러 환경

새로운 VS2017 기능인 "연결 서비스"를 사용하는 경우 환경마다 다른 Application Insight 인스턴스에 어떻게 연결해야합니까?

답변

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

AddTelemetryConfiguration 메서드는 ApplicationInsightsExtensions 클래스에서 찾을 수 있습니다. –

관련 문제