記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\行的代碼
更新時間:2014年03月31日 16:47:42 作者:
這篇文章主要介紹了記錄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("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}", shutDownMessage, shutDownStack), EventLogEntryType.Information);
}
效果截圖
復制代碼 代碼如下:
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("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}", shutDownMessage, shutDownStack), EventLogEntryType.Information);
}
效果截圖

相關(guān)文章
Excel、記事本數(shù)據(jù)導入到數(shù)據(jù)庫的實現(xiàn)方法
將手機號批量導入數(shù)據(jù)庫。思路:先將要導入的文件傳上項目里,然后讀取文件的每行數(shù)據(jù)并插入數(shù)據(jù)庫,操作完后再將上傳的文件刪除2013-10-10ASP.NET GridView的Bootstrap分頁樣式
這篇文章主要為大家詳細介紹了ASP.NET GridView的Bootstrap分頁樣式,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11創(chuàng)建一個完整的ASP.NET Web API項目
ASP.NET Web API具有與ASP.NET MVC類似的編程方式,ASP.NET Web API不僅僅具有一個完全獨立的消息處理管道,而且這個管道比為ASP.NET MVC設(shè)計的管道更為復雜,功能也更為強大。下面創(chuàng)建一個簡單的Web API項目,需要的朋友可以參考下2015-10-10Asp.Net Core中服務(wù)的生命周期選項區(qū)別與用法詳解
這篇文章主要給大家介紹了關(guān)于Asp.Net Core中服務(wù)的生命周期選項區(qū)別與用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-11-11在asp.net中使用加密數(shù)據(jù)庫聯(lián)接字符串保證數(shù)據(jù)安全
加密web.config可以有效保證數(shù)據(jù)庫用戶和密碼安全,下面是示例代碼,大家可以看看2014-09-09