Search code examples
c#asp.netasp.net-core

What is equivalent of HostingEnvironment.ShutdownReason in ASP.NET Core?


In old ASP.NET I could tell why my app stopped by looking at HostingEnvironment.ShutdownReason.

In ASP.NET Core, this doesn't exist. Where can I get this info?


Solution

  • There is no shutdown reason in ASP.NET Core. The good news is, the application dies for a lot less reasons now than it did before because of the new hosting model.

    To put things in perspective, of the events listed on https://learn.microsoft.com/en-us/dotnet/api/system.web.applicationshutdownreason?view=netframework-4.8.1, the ones that are applicable in ASP.NET Core are:

    • None
    • ConfigurationChange (web.config change)

    If we added this, maybe new custom one:

    • AppOffline detected