Log asp.net site is what causes the stop code _ practical Tips

Source: Internet
Author: User
Tags reflection
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
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.