2010-05-26 83 views

回答

2

在ASP.NET中,您可以创建自定义IHttpModule实现,并在其Init方法中注册一个事件处理函数HttpApplication.Error。错误事件触发时根据需要记录异常。

using System; 
using System.Web; 

namespace ConsoleApplication1 
{ 
    public class ErrorLoggingModule : IHttpModule 
    { 
     public void Init(HttpApplication context) 
     { 
      context.Error += OnError; 
     } 

     private static void OnError(object sender, EventArgs e) 
     { 
      Exception ex = HttpContext.Current.Server.GetLastError(); 

      // log exception here... 
     } 

     public void Dispose() 
     {   
     } 
    } 
} 
1

ELMAH(错误日志记录模块和处理)

是应用广泛的错误记录 设施是完全可插入的。 它可以动态地添加到 运行ASP.NET Web应用程序,或 甚至 机器上的所有ASP.NET Web应用程序,而无需任何 重新编译或重新部署。

0

ASP.NET Health Monitoring是非常有用的,你只需要在web.config中配置它。

相关问题