記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\行的代碼
來源:易賢網(wǎng) 閱讀:799 次 日期:2014-10-13 11:39:02
溫馨提示:易賢網(wǎng)小編為您整理了“記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\行的代碼”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\行的具體實現(xiàn)

記錄網(wǎng)站是什么原因?qū)е峦V惯\行還是有必要的,下面是具體的實現(xiàn)方式。

代碼如下:

protected void Application_End(object sender, EventArgs e)

{

RecordEndReason();

}

/// <summary>

/// 記錄網(wǎng)站停止運行原因

/// </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="網(wǎng)站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);

}

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)絡編程

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)