Code that records what caused the asp.net website to stop running
This article mainly explains "recording the code that causes the asp.net website to stop running". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "record the code that causes the asp.net website to stop running".
It is necessary to record what caused the site to stop running. Here are the specific ways to implement it.
The copy code is as follows:
Protected void Application_End (object sender, EventArgs e)
{
RecordEndReason ()
}
/ / /
/ / record the reason why the website stops running
/ / /
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 reason for the restart and the stack information during the restart to the windows event viewer, of course, 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\ nroomshutDownmessage = {0}\ r\ n\ r\ nshutshutDownStack = {1}", shutDownMessage, shutDownStack), EventLogEntryType.Information)
}
Effect screenshot
Thank you for your reading, the above is the content of "recording the code that causes the asp.net website to stop running". After the study of this article, I believe you have a deeper understanding of the problem of recording the code that caused the asp.net website to stop running, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!