Asp.Net Core и Application Insight в VS2017 - несколько сред

До VS2017 в коде можно было настроить интеграцию Application Insight с приложением Asp.NET Core. В VS2017 это возможно только при использовании IDE(подключенных служб), поскольку "Microsoft.ApplicationInsights.AspNetCore"(2.0.0.) Не предлагает builder.AddApplicationInsightsSettings(developerMode: true); расширение больше. Все связанные ресурсы не работают для VS2017(то есть https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started).

При использовании новой функции VS2017 "Подключенные сервисы", как мы должны подключаться к разным экземплярам Application Insights для каждой среды?

1 ответ

Хорошо, все еще возможно установить ApplicationInsights вручную, используя ApplicationInsightsServiceOptions, Вот исходный код, как на самом деле решаются настройки:

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;
}

Таким образом, вы можете видеть наивысший приоритет для переменных среды. Вы можете установить APPINSIGHTS_INSTRUMENTATIONKEY переменная в настройках приложения Azure, и она будет поднята.

Если используется настройка подключенных служб VS2017, она сохраняет свою конфигурацию в csproj, appsettings.json(InstrumentationKey) и /Connected Services/Application Insights/ConnectedServices.json,

Другие вопросы по тегам