記錄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的事件查看器中,當(dāng)然你也可以記錄到文本文件中。
//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);
}
效果截圖
復(fù)制代碼 代碼如下:
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的事件查看器中,當(dāng)然你也可以記錄到文本文件中。
//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)文章
asp.net發(fā)布后web.config中compilation的debug的值true和false區(qū)別點整理
在本篇文章里小編給大家整理的是一篇關(guān)于asp.net發(fā)布后web.config中compilation的debug的值true和false區(qū)別點內(nèi)容,有需要的為朋友們可以參考下。2020-01-01
asp.net中url地址傳送中文參數(shù)時的兩種解決方案
前天遇到一個地址傳遞中文參數(shù)變?yōu)閬y碼的問題,同樣的兩個web Project,一個是vs2003,一個是vs2005,前者可以,后者就是不可以。2009-11-11
asp.net 計算字符串中各個字符串出現(xiàn)的次數(shù)
比如一個字符串"a,b,a,c,b,b,d",現(xiàn)在我們要統(tǒng)計每個字符串出現(xiàn)次數(shù)。解決這個問題,我們可以使用泛型集合 Dictionary(TKey,TValue)。它有一個key值用來存儲字符串和一個value值,用來存儲字符串出現(xiàn)的次數(shù)2012-05-05
ASP.NET使用SignalR2實現(xiàn)服務(wù)器廣播
這篇文章介紹了ASP.NET使用SignalR2實現(xiàn)服務(wù)器廣播的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05

