In line with the ServiceStack documentation, we have a global service exception handler. The docs say that this handler should log the exception then call DtoUtils.HandleException
, like this:
private object LogServiceException(object request, Exception exception)
{
var message = string.Format("Here we make a custom message...");
_logger.Error(message, exception);
return DtoUtils.HandleException(this, request, exception);
}
This results in the error being logged twice, since DTOUtils.HandleException
also logs it, in a less customised format. Yes, I much prefer this to the DTOUtils logging and don't want to just use that.
How do we turn off DTOUtils
logging while retaining the rest of the functionality? Nobody likes getting twice as many error emails as they should.
Do not call
DtoUtils.HandleException
as it logs the error. Don't callServiceRunner.HandleException
either, it callsDtoUtils.HandleException
.Call
DtoUtils.CreateErrorResponse
to make the response (it is used byDtoUtils.HandleException
). TheToResponseStatus
helper is also inDtoUtils
My AppServiceRunner is now like this:
Now the only service errors that I get are those generated by this code.
I hope the following code solves your problem.
based on the documentation New API, Custom Hooks, ServiceRunner
and Fine grain error handling using the New API's ServiceRunner
in AppHost.Configure
then in AppHost class
in the ServiceRunner class
if you return the base.HandleException, it calls internally the DtoUtils.HandleException. You will see in console, one log error only.
In client, if you handle the WebServiceException for custom errors.