Настройте аналитические данные приложений с помощью веб-задания Azure

#azure #azure-webjobs

#лазурный #azure-webjobs

Вопрос:

Я пытаюсь настроить Application Insights для моего webjob (Microsoft.Лазурный.Веб — задания (v:2.3 )

 if (!string.IsNullOrEmpty(instrumentationKey))
{
    // Wire up with default filters; Filtering will be explained later.
    config.LoggerFactory = new LoggerFactory()
                .AddApplicationInsights(instrumentationKey, null)
                .AddConsole();

    config.Tracing.ConsoleLevel = TraceLevel.Off;
}
  

LoggerFactory недоступен.

Я установил приведенный ниже пакет.

 <package id="Microsoft.ApplicationInsights" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.4.1" targetFramework="net471" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.4.0" targetFramework="net471" />
<package id="Microsoft.Azure.WebJobs.Logging" version="3.0.6" targetFramework="net471" />
<package id="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" version="2.3.0" targetFramework="net471" />
  

Спасибо!

Ответ №1:

Необходимо установить следующие пакеты NuGet:

  • Майкрософт.Azure.Веб-задания.Ведение журнала.ApplicationInsights
  • Майкрософт.Расширения.Ведение журнала
  • Майкрософт.Расширения.Ведение журнала.Консоль

Посмотрите здесь.

Ответ №2:

Кажется, что отсутствует конфигурация JobHostConfiguration var config = new JobHostConfiguration();

В противном случае вы можете выполнить настройку, как показано в следующем фрагменте

 var builder = new HostBuilder().ConfigureLogging((context, b) =>
{
    b.AddConsole();

    // If the key exists in settings, use it to enable Application Insights.
    var instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
    if (!string.IsNullOrEmpty(instrumentationKey))
    {
        b.AddApplicationInsights(o => o.InstrumentationKey = instrumentationKey);
    }
})