I am working with WebApi and ELMAH and I would like to be able to wrap some business errors into web responses for some thypes of exceptions(no logging) and have the others logged by ELMAH. Right no I have this piece of code.
public async override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
{
try
{
return await base.ExecuteAsync(controllerContext, cancellationToken);
}
catch (MyException ex)
{
return new HttpResponseMessage(CustomCode)
{
Content = new StringContent(CustomMessage)
};
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
return new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("Ups! Something went wrong. Please try again or contact administrator!")
};
}
}
The problem is I would expect ELMAH to log only unhandled exceptions. In my case, even the exception of type MyException is being logged, although it is caught by the catch block.
Is there any config I can apply to ELMAH to make it log only unhandled eceptions ?