How can I record the reason why the Asp.net site is restarted?

Source: Internet
Author: User

Add the record method in the application_end event on the site. Add the following Code to the Global. asax. CS file:

Void application_end (Object sender, eventargs e) {// code that runs on application shutdown recordendreason ();} protected void recordendreason () {httpruntime runtime = (httpruntime) typeof (system. web. httpruntime ). invokemember ("_ theruntime", bindingflags. nonpublic | bindingflags. static | bindingflags. getfield, null); If (runtime = NULL) return; string shutdownmessage = (string) runtime. getType (). invokemember ("_ shutdownmessage", bindingflags. nonpublic | bindingflags. instance | bindingflags. getfield, null, runtime, null); string shutdownstack = (string) runtime. getType (). invokemember ("_ shutdownstack", bindingflags. nonpublic | bindingflags. instance | bindingflags. getfield, null, runtime, null); 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 );}

the above 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.

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.