Up until .NET 4.8 you were able to get the shutdown reason via HostingEnvironment.ShutdownReason
The question has been answered before here for .NET Framework 4.8.
In ASP.NET Core this property is no longer available. This question has been asked before for ASP.NET Core here but didn't get answered.
It's possible to register to IHostApplicationLifetime to be notified when ASP.NET is shutting down but this does not provide you the shutdown reason.
The answer to a similar question in 2017 only concerned Kestrel hosting: There is no shutdown reason in ASP.NET Core because most of the original reasons don't apply.
Is there any way to know why IIS shut down the web app when in-process hosting is used?