开发工具 VS2003 B/S WEB项目
每次把项目发布到客户服务器上,通常都会对项目跟踪一段时间。
在实施过程中,对于项目中出现的程序问题,能保证第一时间通知给相关的技术负责人,很重要。
在ASP.NET WEB项目Global.asax 类中有一个Application_Error的事件,可以捕获到所有程序上的错误。
对于发送给技术人员的邮件,一般需要提供:
1:用户的IP地址
2:操作人员的姓名
3:程序的完整路径
4:程序错误发生的时间
5:程序错误的完整信息
protected void Application_Error(Object sender, EventArgs e)
{
string UserName = "xxxxxxx";
Exception ErrorInfo = Server.GetLastError();
string Message = ErrorInfo.ToString();
System.Web.Mail.MailMessage mail=new System.Web.Mail.MailMessage();
mail.From="986661678@QQ.COM";
mail.To="TGL2008@VIP.QQ.COM";
mail.Subject = "湖南人民出版社("+UserName+Request.UserHostAddress.ToString() + ") 程序异常:"
+ GetPath() + " "
+ System.DateTime.Now.ToString("yyyy-MM-dd hh:mm");
mail.BodyFormat=System.Web.Mail.MailFormat.Text;
mail.Body = Message;
System.Web.Mail.SmtpMail.SmtpServer="smtp.qq.com";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "986661678");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxxxxxx");
//把错误信息发送给技术人员 TGL2008@VIP.QQ.COM
System.Web.Mail.SmtpMail.Send(mail);
}