您可以在 Global.asax.cs 的 Application_End 方法中记录重启原因,我正在使用此代码:
protected void Application_End(object sender, EventArgs e)
{
HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
string shutDownMessage = "";
if (runtime != null)
{
shutDownMessage = Environment.NewLine + "Shutdown: " +
(string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) +
Environment.NewLine + "Stack: " + Environment.NewLine +
(string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
}
}