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

时间:2019-07-14 21:56:12

标签: c# asp.net-core kubernetes google-kubernetes-engine 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...

有什么办法可以使我了解为什么应用程序被关闭?我知道您可以在Shutdown上注册事件处理程序,例如:

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
    }
}

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

1 个答案:

答案 0 :(得分:1)

问题是默认情况下,我的ASP.NET Core Web Api项目不处理根路径。因此/被健康检查所击中,并且当它没有得到200 OK时,GKE应该击倒Kubernetes吊舱。