그래도 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
에 구성을 저장합니다.
AddTelemetryConfiguration 메서드는 ApplicationInsightsExtensions 클래스에서 찾을 수 있습니다. –