主页 > 知识库 > 记录asp.net网站是什么原因导致停止运行的代码

记录asp.net网站是什么原因导致停止运行的代码

热门标签:昆明语音电销机器人价格 征途美甲店地图标注 百度地图怎样做地图标注 400电话如何申请取消 太原400电话上门办理 腾讯地图标注手机 浦发电话机器人提醒还款 柳州电销机器人公司 电销语音机器人型号参数
记录网站是什么原因导致停止运行还是有必要的,下面是具体的实现方式。
复制代码 代码如下:

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("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}", shutDownMessage, shutDownStack), EventLogEntryType.Information);
}

效果截图
您可能感兴趣的文章:
  • asp.net获取网站绝对路径示例
  • Web Deploy发布网站及常见问题解决方法(图文)
  • VS2010发布Web网站技术攻略

标签:江苏 德阳 兰州 白山 新疆 阳泉 天门 张家界

巨人网络通讯声明:本文标题《记录asp.net网站是什么原因导致停止运行的代码》,本文关键词  记录,asp.net,网站,是什么,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《记录asp.net网站是什么原因导致停止运行的代码》相关的同类信息!
  • 本页收集关于记录asp.net网站是什么原因导致停止运行的代码的相关信息资讯供网民参考!
  • 推荐文章