azure - 使用 Application Insights 根据 WebJob 日志中的错误监控 Azure WebJobs 运行状况
问题描述
按照此文档,我配置了多步 Web 测试,以使用 Azure Application Insights 监控 Azure Web 作业运行状况。但是这个多步骤的 Web 测试只会检查 Azure Web Job 的状态,是否是“正在运行、失败和中止”。
有时,Azure Web 作业被中止。但工作在其中运行。因此,我需要使用 Multi-step web test 根据日志中的错误监控 Azure Web Job 的状态,如下图所示。
解决方案
你可以Application Insights Integration
用来实现它。LogCategoryFilter 具有初始值为 Information 的 Default 属性,这意味着将记录任何具有 Information、Warning、Error 或 Critical 级别的消息。
你总共需要三个包:
- Microsoft.Azure.WebJobs.Logging.ApplicationInsights
- Microsoft.Extensions.Logging
- 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
网络作业。
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...");
}
这是我的网络作业日志。
这是 Application Insight 页面。您会发现信息、警告和异常都显示在那里。
推荐阅读
- visual-studio-code - 如果打开,是否有 VSCode 操作来关闭侧边栏,否则什么都不做?
- mysql - 创建新列和比较
- html - 源代码中的换行符在右对齐并使用时呈现为无宽度空白
- python - 合并列、pickup_date 和pickup_time = + 不支持的操作数类型:“DatetimeIndex”和“str”
- node.js - 我可以使用 Mongo DB 设置服务器以使用 three.js 库进行开发吗?
- python - 如何在 pandas 数据帧上生成具有随机值的合成数据?
- android - 我们如何使用 setLaunchDisplayId() 将 Activity 显示为横向?
- spring-boot - Spring Security 5 OpenId 资源服务器 Websecurity dsl
- javascript - JavaScript 中是否有一种方法可以在相对较快的时间内获得大量 BigInt 类型的表示?
- reactjs - 在反应路由器上找不到处理资源