使用Application Insights根据WebJob日志中的错误监控Azure WebJobs Health

问题描述 投票:0回答:1

我按照此documentation配置了使用Azure Application Insights监控Azure Web作业健康状况的多步Web测试。但是,这个多步骤Web测试将仅检查Azure Web作业的状态,无论是“运行,失败和中止”。

有时,Azure Web作业已中止。但是这项工作在其中运行。因此,我需要根据日志中的错误监视Azure Web Job的状态,如下图所示,使用多步Web测试。 enter image description here

azure azure-webjobs azure-application-insights azure-webjobs-triggered
1个回答
0
投票

您可以使用Application Insights Integration来实现它。 LogCategoryFilter具有Default属性,其初始值为Information,这意味着将记录任何级别为Information,Warning,Error或Critical的消息。

你总共需要三个包:

  1. Microsoft.Azure.WebJobs.Logging.ApplicationInsights
  2. Microsoft.Extensions.Logging
  3. Microsoft.Extensions.Logging.Console

配置JobHostConfiguration

string instrumentationKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");
if (!string.IsNullOrEmpty(instrumentationKey))
{
      // build up a LoggerFactory with ApplicationInsights and a Console Logger
       config.LoggerFactory = new LoggerFactory().AddApplicationInsights(instrumentationKey, null).AddConsole();
       config.Tracing.ConsoleLevel = TraceLevel.Off;
}

注意:不要忘记在应用程序设置中添加APPINSIGHTS_INSTRUMENTATIONKEY

我测试ProcessQueueMessage webjob。

public static void ProcessQueueMessage([QueueTrigger("myqueue")] string message, ILogger logger)
    {
        logger.LogInformation("it is a error......");
        logger.LogError(new Exception(), "it is a test error...");
    }

这是我的webjob日志。

enter image description here

这是Application Insight页面。你可以在那里看到信息,警告和例外。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.