Using Elmah with ServiceStack.Mvc

僤鯓⒐⒋嵵緔 提交于 2019-12-06 07:31:38

问题


I could not see unhandled exceptions ( MyService:RestServiceBase) on /elmah.axd path.

I've added http handlers for seeing errors.

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

I've installed ServiceStack.Logging.Elmah

UPDATE

I've installed Elmah.Mvc package also

I can get errors in Controller's Action but I could not get service errors!

UPDATE

I'm not alone :) https://groups.google.com/forum/#!topic/servicestack/WSrM5CLL120


回答1:


You need subscribe to AppHostBase.ServiceExceptionHandler events in Configure method which normally resides in AppHost class:

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

    ....
}


来源:https://stackoverflow.com/questions/12080911/using-elmah-with-servicestack-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!