如何手动从 ELMAH 中获取记录的条目

发布于 2024-11-08 12:44:53 字数 1343 浏览 5 评论 0原文

这看起来很简单。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2024-11-15 12:44:53

假设您将数据存储在默认表 ELMAH_Error 中

SELECT AllXml
FROM ELMAH_Error

Assuming you store the data in the default table ELMAH_Error

SELECT AllXml
FROM ELMAH_Error
一抹淡然 2024-11-15 12:44:53

最终解决方案如下:

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( );
}

The solution ended up being as follows:

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( );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文