admin管理员组文章数量:1530842
Global.ascx页面使用以下方法即可捕获应用层没有try cath的错误
protected void Application_Error(Object sender, EventArgs e)
{//在出现未处理的错误时运行的代码
Exception ex = Server.GetLastError();
Exception exp = ex.GetBaseException();
if (exp.GetType().Name.Equals("HttpException"))
{//排除404页面
if (404 == ((HttpException)exp).GetHttpCode()) { return; }
}
StringBuilder sbReqParams = new StringBuilder();
sbReqParams.Append("\r\nUser-Agent:" + HttpUtility.UrlDecode(this.Request.UserAgent));
sbReqParams.Append("\r\nForm:"+ HttpUtility.UrlDecode(this.Request.Form.ToString()));
sbReqParams.Append("\r\nCookies:"+ HttpUtility.UrlDecode(this.Request.Form.ToString()));
LogHelper.WriteLog(string.Format("应用程序出错:\r\n错误页面:{0}\r\n请求参数:{1}\r\n", this.Request.Url, sbReqParams.ToString()), ex);
Server.ClearError();
}
本文标签: 错误站点日志ApplicationError
版权声明:本文标题:使用Application_Error捕获站点错误并写日志 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1725431574a1022956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论