这看起来很简单。 Elmah记录错误,我在elmah.axd文件中看到错误,然后我想将数据抓取到新的自定义视图中。
我无法弄清楚如何抓住Elma的细节页面。到目前为止,我所能做的就是获取我想要的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 :(得分:0)
假设您将数据存储在默认表ELMAH_Error
中SELECT AllXml
FROM ELMAH_Error
答案 1 :(得分: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( );
}