Log asp.net web site What caused the code to stop running

Source: Internet
Author: User
Tags reflection

  This article mainly describes the record of the ASP.net web site is the reason why the implementation of the stop operation of the concrete

It is necessary to keep track of what causes the site to stop running, and here is how to implement it. The   code is as follows: protected void Application_End (object sender, EventArgs e)   {  Recordendreason (); }  &N Bsp <summary> ///Record website stop running reason  ///</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 ("Rnrn_shutdownmessage={0}rnrn_shutdownstack={1}", Shutdownmessage, Shutdownstack), eventlogentrytype.information); }   
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.