2011-05-19 49 views
1

這似乎很簡單。 Elmah記錄錯誤,我在elmah.axd文件中看到錯誤,然後我想將數據提取到新的自定義視圖中。如何手動抓取ELMAH的日誌條目

我無法弄清楚如何從Elma中抓取Detail Page。迄今爲止,所有能夠做到的都是獲取我想要的ErrorLogEntry,但無法弄清楚如何獲得服務器吐出的實際XML /異常錯誤。

Elmah設置正常。但我有:

<customErrors mode="On" defaultRedirect="~/Error/Index"> 
    <error statusCode="404" redirect="~/Error/NotFound"></error> 
</customErrors> 

都到我的簡單ErrorController.cs類:

public virtual ActionResult Index() 
{ 
    Exception ex = null; 

    try 
    { 
     Elmah.ErrorLogDataSourceAdapter eldsa = new Elmah.ErrorLogDataSourceAdapter(); 
     ErrorLogEntry[] errors = eldsa.GetErrors(0, 1); 

     foreach (ErrorLogEntry ele in errors) 
     { 
      ViewData[ "Description" ] += ele.Error.Message + "<br />"; 
      ViewData[ "Description" ] += ele.Error.WebHostHtmlMessage + "<br />"; 
      Elmah.ErrorLogPageFactory pf = new ErrorLogPageFactory(); 

     } 
    } 
    catch 
    { 
     ViewData[ "Description" ] = "An error occurred."; 
    } 

    ViewData[ "Title" ] = "Oops. We're sorry. An error occurred and we're on the case."; 

    //Email.SendException(ex, "Error in PRISM.NET"); 
    return View(); 
} 

出現的問題是,WebHostHtmlMessage是空的。所以我不能得到異常消息。

我一直在尋找內部Elmah代碼整天,我不知道如何手動創建一個頁面,就像Elmah在調用elmah.axd時所做的那樣。

回答

0

假設你的數據存儲在默認表ELMAH_Error

SELECT AllXml 
FROM ELMAH_Error 
+0

而是我要搶出數據的ELMAH類的不做老式的方式。 – dharh 2011-05-19 22:01:26

0

該解決方案最終被如下:

public virtual ActionResult Index() 
{ 
    Exception ex = null; 

    try 
    { 
     Elmah.ErrorLogDataSourceAdapter eldsa = new Elmah.ErrorLogDataSourceAdapter(); 
     ErrorLogEntry[] errors = eldsa.GetErrors(0, 1); 

     foreach (ErrorLogEntry ele in errors) 
     { 
      ErrorLogEntry thisError = ErrorLog.GetError(ele.Id); 
      ex = new Exception(thisError.Error.WebHostHtmlMessage); 
     } 
    } 
    catch 
    { 
     ViewData[ "Description" ] = "An error occurred."; 
    } 

    ViewData[ "Description" ] = "Oops. We're sorry. An error occurred and we're on the case."; 

    Email.SendException(ex, "Error in PRISM.NET"); 
    return View(); 
}