当前位置: 移动技术网 > IT编程>开发语言>.net > 记录asp.net网站是什么原因导致停止运行的代码

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

男人之苦粤语,清平乐 辛弃疾,足球宝贝杨棋涵视频

记录网站是什么原因导致停止运行还是有必要的,下面是具体的实现方式。
复制代码 代码如下:

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);
}

效果截图

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网