萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> 記錄asp.net網站是什麼原因導致停止運行的代碼

記錄asp.net網站是什麼原因導致停止運行的代碼

 這篇文章主要介紹了記錄asp.net網站是什麼原因導致停止運行的具體實現

記錄網站是什麼原因導致停止運行還是有必要的,下面是具體的實現方式。  代碼如下: protected void Application_End(object sender, EventArgs e)  {  RecordEndReason();  }    /// <summary>  /// 記錄網站停止運行原因  /// </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="網站Application_End,停止運行,shutDownMessage=" + shutDownMessage + ",shutDownStack=" + shutDownStack;  LogHelper.WriteErrorLog(reasonString,null);  LogHelper.WriteSmtp(reasonString, null);  //以下方法將重啟的原因和重啟時的堆棧信息記錄到了windows的事件查看器中,當然你也可以記錄到文本文件中。  //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);  }   
copyright © 萬盛學電腦網 all rights reserved