如何获取 ASP.NET Core 应用程序关闭的原因?

nik*_*3ro 8 c# kubernetes google-kubernetes-engine asp.net-core asp.net-core-2.2

我已将 ASP.NET Core 2.2 应用程序容器化到 Docker 映像中,然后将其部署到 Google Kubernetes Engine。应用程序定期启动,但有时它会随机关闭。日志没有给出有关正在发生的事情的特殊提示,我得到的只是:

I 2019-07-11T19:36:07.692416088Z Application started. Press Ctrl+C to shut down. 
I 2019-07-11T20:03:59.679718522Z Application is shutting down...
Run Code Online (Sandbox Code Playgroud)

有什么方法可以了解应用程序关闭的原因吗?我知道您可以在关机时注册事件处理程序,例如:

public class Startup
{
    public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime)
    {
        applicationLifetime.ApplicationStopping.Register(OnShutdown);
    }

    private void OnShutdown()
    {
         //this code is called when the application stops
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我如何从那里提取应用程序关闭的原因呢?

nik*_*3ro 8

问题是默认情况下我的 ASP.NET Core Web Api 项目不处理根路径。因此/受到健康检查的影响,当它没有恢复时,200 OKGKE 应该关闭 Kubernetes pod。