2010-05-26 51 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中配置它。

相關問題