记录asp.net网站停止运行原因的代码
2014-03-27 10:36
148 查看
记录网站是什么原因导致停止运行还是有必要的,下面是具体的实现方式。
效果截图
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网站是什么原因导致停止运行的代码
- 如何让ASP.NET网站站点不停止 永远持续运行
- 浅析linux上如何让apache运行aspx网站即asp.net代码
- 在asp.net里使用指定的用户运行访问Sharepoint网站的代码
- ASP.NET MVC 拦截器中如何停止往后面的代码运行!
- SVN 导出代码在VS2012运行提示“未能将网站xx 配置为使用 ASP.NET 4.0,为了使此网站正确运行,您必须将它手动配置为使用 ASP.NET 4.0”
- 一种基于自定义代码的asp.net网站首页根据IP自动跳转指定页面的方法!
- 一种基于自定义代码的asp.net网站首页根据IP自动跳转指定页面的方法!
- 网站优化记录-通过命令预编译Asp.net 网站,成功优化到毫秒级别。
- VS2012 未能将网站XXX配置为使用ASP.NET 4.5.为了使此网站正确运行.你必须将它手动配置为使用ASP.NET 4.5
- 解决调试asp.net程序时无法修改代码的问题(提示: 当调试器已经附加到已经运行的进程...)
- ASP.NET程序运行出现WebDev.WebServer40.exe已停止工作解决方法(netsh winsock reset)
- asp.net gridview实现全选,反选与删除记录的操作代码
- https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题
- 通过避免下列 10 个常见 ASP.NET 缺陷使网站平稳运行
- VS2012 未能将网站XXX配置为使用ASP.NET 4.5.为了使此网站正确运行,您必须将它手动配置为ASP.NET 4.5
- 不修改代码就能优化ASP.NET网站性能的一些方法
- 通过避免下列 10 个常见 ASP.NET 缺陷使网站平稳运行(转)
- 从.Net类库代码来看Asp.net运行时