It is necessary to keep track of what causes the site to stop running, and here is how to implement it.
Copy Code code as follows:
protected void Application_End (object sender, EventArgs e)
{
Recordendreason ();
}
<summary>
Recording why the site stopped running
</summary>
protected void Recordendreason ()
{
HttpRuntime runtime = (HttpRuntime) typeof (System.Web.HttpRuntime). InvokeMember ("_theruntime", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.GetField,
Null
Null
NULL);
if (runtime = null)
Return
String shutdownmessage = (string) runtime. GetType (). InvokeMember ("_shutdownmessage",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField,
Null
Runtime
NULL);
String shutdownstack = (string) runtime. GetType (). InvokeMember (
"_shutdownstack",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField,
Null
Runtime
NULL);
String reasonstring= "website Application_End, stop running, shutdownmessage=" + Shutdownmessage + ", shutdownstack=" + shutdownstack;
Loghelper.writeerrorlog (Reasonstring,null);
LOGHELPER.WRITESMTP (reasonstring, NULL);
The following methods record the reason for the reboot and the stack information when it restarts in Windows Event Viewer, but you can also record it in a text file.
EventLog log = new EventLog ();
Log. Source = "asp.net 2.0.50727.0";
Log. WriteEntry (String.Format ("\r\n\r\n_shutdownmessage={0}\r\n\r\n_shutdownstack={1}", Shutdownmessage, Shutdownstack), eventlogentrytype.information);
}
Screenshot of Effect