azure - 在 Azure 应用程序见解中查找“应用程序停止事件”
问题描述
我有一个有时会经历“平台(基础设施升级)”事件的 Web 应用程序。
我可以检测到这些的唯一方法是转到 Azure 门户并向下钻取
- 诊断和解决问题 > Web App 重启
并寻找如下错误
我的问题是,我是否可以使用 Application Insights 查询 Azure 以了解这些事件何时发生?
看似简单的事情,却想不通。
解决方案
我可以使用 Application Insights 查询 Azure 以了解这些事件何时发生吗?
不,但是您的应用程序可能能够在启动或关闭时记录事件?例如,在 .Net Core 应用程序中,您可以像这样监听停止/启动事件:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime, TelemetryClient telemetryClient)
{
hostApplicationLifetime.ApplicationStarted.Register(() => { telemetryClient.TrackEvent("App Started"); });
hostApplicationLifetime.ApplicationStopping.Register(() => { telemetryClient.TrackEvent("App Stopping"); });
hostApplicationLifetime.ApplicationStopped.Register(() => {
telemetryClient.TrackEvent("App Stopped");
telemetryClient.Flush();
Thread.Sleep(TimeSpan.FromSeconds(5));
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
它使用IHostApplicationLifetime接口来获取应用程序生命周期事件的通知。
推荐阅读
- javascript - React Navigation V5 在 Stack Navigator 中隐藏底部标签栏
- maven - 尝试在 Go CD 中执行“mvn clean package”时发生错误
- statistics - 多元回归相关效应
- python - 使用 Postgresql、SQLAlchemy 和 Pandas 进行 Dash 实时更新未更新
- react-native - 从 FlatList 重新加载数据 - React Native
- c# - ASP.Net Core 3.1 WEB API - 控制器方法不返回正确的 JSON
- c - 是否可以在 C 中完全缓冲的输出流甚至在缓冲区完全填充之前自动刷新?
- aframe - 如何在 aframe-v1.1.0.min 中使用 collada 模型
- sql - 如何根据 Oracle SQL 中的模式提取两个字符串之间的数据
- laravel - 错误:无法解析的依赖关系解析文件 Container.php 中 class JsonResource 中的 $resource