記錄網(wǎng)站是什么原因?qū)е峦V惯\(yùn)行還是有必要的,下面是具體的實(shí)現(xiàn)方式。
復(fù)制代碼 代碼如下:
protected void Application_End(object sender, EventArgs e)
{
RecordEndReason();
}
/// summary>
/// 記錄網(wǎng)站停止運(yùn)行原因
/// /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,停止運(yùn)行,shutDownMessage=" + shutDownMessage + ",shutDownStack=" + shutDownStack;
LogHelper.WriteErrorLog(reasonString,null);
LogHelper.WriteSmtp(reasonString, null);
//以下方法將重啟的原因和重啟時(shí)的堆棧信息記錄到了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);
}
效果截圖
您可能感興趣的文章:- asp.net獲取網(wǎng)站絕對(duì)路徑示例
- Web Deploy發(fā)布網(wǎng)站及常見(jiàn)問(wèn)題解決方法(圖文)
- VS2010發(fā)布Web網(wǎng)站技術(shù)攻略