It is necessary to record the reason why the website stops running. The following is a specific implementation method.
Protected void Application_End (object sender, EventArgs e) {RecordEndReason ();} /// <summary> // record the reason why the website stops 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); 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 method records the cause of the restart and the stack information during the restart to the windows event viewer. Of course, you can also record it to 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 );}
Effect