如何手动从 ELMAH 中获取记录的条目
这看起来很简单。 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 时所做的那样。
This seems simple enough. Elmah logs the errors, I see the error in the elmah.axd file, I then want to grab the data out into a new custom view.
I can't figure out how to grab the Detail Page out of Elma. Thus far all ive been able to do is get the ErrorLogEntry I want but cannot figure out how to get the actual XML/Exception error the server spit out.
Elmah is set up normally. But I have:
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/NotFound"></error>
</customErrors>
Which goes to my simple ErrorController.cs class:
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( );
}
The problem that occurs is that WebHostHtmlMessage is empty. So I cant get the Exception message.
I've been looking inside Elmah code all day and I can't figure out how to manually create a page just like it Elmah does when elmah.axd is called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您将数据存储在默认表 ELMAH_Error 中
Assuming you store the data in the default table ELMAH_Error
最终解决方案如下:
The solution ended up being as follows: