使用Elmah与ServiceStack.Mvc

3

我无法在/elmah.axd路径上看到未处理的异常(MyService: RestServiceBase)。

我已添加HTTP处理程序以查看错误。

 <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

我已安装了ServiceStack.Logging.Elmah。
更新:
我还安装了Elmah.Mvc包。
我可以在控制器的操作中获取错误,但是我无法获取服务错误!
更新:
我不是唯一一个遇到这个问题的人 :) https://groups.google.com/forum/#!topic/servicestack/WSrM5CLL120
1个回答

4

您需要在通常位于AppHost类中的Configure方法中订阅AppHostBase.ServiceExceptionHandler事件:

public class AppHost : AppHostBase
{
    ....

    public override void Configure(Funq.Container container)
    {
        ServiceExceptionHandler += (request, exception) =>
        {
            //pass the exception over to Elmah
            var context = HttpContext.Current;
            Elmah.ErrorLog.GetDefault(context).Log(new Error(exception, context));

            //call default exception handler or prepare your own custom response
            return DtoUtils.HandleException(this, request, exception);
        };
    }

    ....
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接