Record what causes the asp.net website to stop running code

Source: Internet
Author: User

It is necessary to record the reason why the website stops running. The following is a specific implementation method.
Copy codeThe Code is as follows:
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,
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 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 the information 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 );
}

Effect

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.