Global.asax文件中加入
///
/// 系统错误日志记录
/// ///
///
protected void Application_Error(Object sender, EventArgs e)
{
//错误的全局处理
Exception ex = Server.GetLastError().GetBaseException() ;
//记录错误日志
string strFile = Request.ApplicationPath + "/sys_error.log";
strFile = Server.MapPath(strFile);
System.IO.StreamWriter st = new System.IO.StreamWriter (strFile,true,System.Text.Encoding.UTF8);
string sText ="" ;
sText += "\r\n//----------------------------------------------------------------------------\r\n";
sText += "//----------------------------------------------------------------------------\r\n";
sText += "系统出现如下错误:\r\n";
sText += " 发生时间 : " + DateTime.Now.ToString() + "\r\n";
sText += " 错误描述 : " + ex.Message.Replace("\r\n","") + "\r\n";
sText += " 错误对象 : " + ex.Source + "\r\n";
sText += " 错误帮助 : " + ex.HelpLink + "\r\n";
sText += " 错误页面 : " + Request.UrlReferrer + "\r\n";
sText += " 用户 IP : " + Request.UserHostAddress + "\r\n";
sText += " 用户 IE : " + Request.UserAgent + "\r\n";
sText += " 详细描述 :\r\n" + ex.StackTrace + "\r\n";
sText += "\r\n";
st.Write(sText);
st.Close();
Response.Write ("");
Response.End();
}
本文作者:佚名 来源:http://gzycm520.blog.51cto.com/175220/37632
CIO之家 www.ciozj.com 微信公众号:imciow