程序中错误信息的处理办法
来源:互联网 发布:淘宝上的实体娃娃 编辑:程序博客网 时间:2024/05/18 02:51
将错误发送给开发者
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Web.Mail ;
using System.Diagnostics ;
namespace WebApplicationI
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
}
protected void Session_Start(Object sender, EventArgs e)
{
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
//把错误信息发送到作者
string strPageUrl = Request.Path;
Exception ErrorInfo =Server.GetLastError();
//Server.ClearError();
string strMessage = "Url:" + strPageUrl + "</br>";
strMessage = strMessage + " Error: ";
strMessage = strMessage + ErrorInfo.ToString() + "</br>";
MailMessage Mymessage = new MailMessage();
Mymessage.To = "***@***.com.cn";
Mymessage.From = "***@***.com.cn";
Mymessage.Subject = "ASP.NET Error";
Mymessage.BodyFormat = MailFormat.Text;
Mymessage.Body = strMessage;
//SmtpMail.SmtpServer = " ";
SmtpMail.Send(Mymessage);
}
protected void Session_End(Object sender, EventArgs e)
{
}
protected void Application_End(Object sender, EventArgs e)
{
}
Web 窗体设计器生成的代码
}
}
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Web.Mail ;
using System.Diagnostics ;
namespace WebApplicationI
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
}
protected void Session_Start(Object sender, EventArgs e)
{
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
//把错误信息发送到作者
string strPageUrl = Request.Path;
Exception ErrorInfo =Server.GetLastError();
//Server.ClearError();
string strMessage = "Url:" + strPageUrl + "</br>";
strMessage = strMessage + " Error: ";
strMessage = strMessage + ErrorInfo.ToString() + "</br>";
MailMessage Mymessage = new MailMessage();
Mymessage.To = "***@***.com.cn";
Mymessage.From = "***@***.com.cn";
Mymessage.Subject = "ASP.NET Error";
Mymessage.BodyFormat = MailFormat.Text;
Mymessage.Body = strMessage;
//SmtpMail.SmtpServer = " ";
SmtpMail.Send(Mymessage);
}
protected void Session_End(Object sender, EventArgs e)
{
}
protected void Application_End(Object sender, EventArgs e)
{
}
Web 窗体设计器生成的代码
}
}
将错误写入系统日志
string strMessage = Server.GetLastError().Message;
//Response.Write(strMessage);
Server.ClearError();
//以下把信息写入windows日志
//要把aspnet用户添加到管理员组中,以便有写注册表权限
if(!EventLog.SourceExists("mySource"))
EventLog.CreateEventSource("mySource","myLog");
EventLog Event = new EventLog();
Event.Source = "mySource";
Event.WriteEntry( System.DateTime .Now .ToString (),EventLogEntryType.Warning);
//EventLog.Delete("myLog");
//throw new Exception("我处理不了!");
//Response.Write(strMessage);
Server.ClearError();
//以下把信息写入windows日志
//要把aspnet用户添加到管理员组中,以便有写注册表权限
if(!EventLog.SourceExists("mySource"))
EventLog.CreateEventSource("mySource","myLog");
EventLog Event = new EventLog();
Event.Source = "mySource";
Event.WriteEntry( System.DateTime .Now .ToString (),EventLogEntryType.Warning);
//EventLog.Delete("myLog");
//throw new Exception("我处理不了!");
将错误信息写入输出窗口
System.Diagnostics .Debug .WriteLine( 想要输出的值);
将错误信息写入目录下的log
System.Diagnostics.Trace.Listeners.Clear();
System.Diagnostics.Trace.AutoFlush=true;
string strPath = string.Empty;
strPath = Page.Server.MapPath (".") ;
strPath += @"/app.log";
FileStream fs = new FileStream( strPath, FileMode.Append , FileAccess.Write );
System.Diagnostics .Trace.Listeners.Add( new System.Diagnostics .TextWriterTraceListener( fs ) );
System.Diagnostics .Trace .WriteLine("star");
System.Diagnostics .Trace .WriteLine(System.DateTime.Now.ToLongTimeString () );
System.Diagnostics .Trace .WriteLine( Page.ToString());
System.Diagnostics .Trace .WriteLine("end");
fs.Close ();
System.Diagnostics.Trace.AutoFlush=true;
string strPath = string.Empty;
strPath = Page.Server.MapPath (".") ;
strPath += @"/app.log";
FileStream fs = new FileStream( strPath, FileMode.Append , FileAccess.Write );
System.Diagnostics .Trace.Listeners.Add( new System.Diagnostics .TextWriterTraceListener( fs ) );
System.Diagnostics .Trace .WriteLine("star");
System.Diagnostics .Trace .WriteLine(System.DateTime.Now.ToLongTimeString () );
System.Diagnostics .Trace .WriteLine( Page.ToString());
System.Diagnostics .Trace .WriteLine("end");
fs.Close ();
- 程序中错误信息的处理办法
- BADI 中错误信息的处理
- BADI 中错误信息的处理
- 连接oracle时出现 ORA-12514 错误信息的原因及处理办法
- “存储并显示最近在开始菜单中打开的程序”显示为灰色的处理办法
- 在ashx一般处理程序文件中不能使用session和request的问题解决办法
- java中字符串的处理办法
- firefox中div重叠的处理办法
- 链接中存在中文的处理办法
- 多重处理系统中,处理死锁的办法
- 多重处理系统中,处理死锁的办法
- 调试程序时总会提示代码过期的处理办法....
- [转]QTP处理定时运行程序的办法
- 在Global中Application_Error事件处理错误信息
- 探讨在项目中如何处理错误信息
- 错误信息处理
- 错误信息处理
- 在XCode4中添加程序调试错误信息
- 关于winpcap 的郁闷问题
- Asp.net 2.0 C#实现压缩/解压功能 (示例代码下载)
- 串口一拖二收发数据测试总结
- c#探针
- DirectX图形处理(1)
- 程序中错误信息的处理办法
- DirectX图形处理(2)
- DirectX图形处理(3)
- DirectX图形处理(4)
- DirectX图形处理(5)
- DirectX图形处理(6)
- asp.net 函数集
- OpenGL-视点的建立
- DirectX图形处理(7)