my question should be quite simple, but unfortunately I had no luck in solving it.
Basically, I have some Web API controllers hosted by OWIN and deployed on Azure.
I really need to track down exceptions that occur in each middleware (for example OAuthAuthorizationServerProvider or SignalR Persistent Connections), but I definitely don't have a clue on how to achieve it.
- I tried Elmah, but it doesn't seem to work properly with OWIN due to lacking HttpContext.
- I tried using log4net, but I'm only able to log exceptions thrown by Web API Controllers using a custom ExceptionFilterAttribute.. others are ignored.
- I tried to define a custom LoggerFactory and to assign it in Startup, using
app.SetLoggerFactory(new MyLoggerFactory())
, but exception thrown by other middlewares are not logged. - I tried to get at least a meaningful error message sent to the client, but despite
<customErrors mode="Off"/>
and<deployment retail="false"/>
, Azure refuses to return anything but{"message":"an error has occurred"}
.. I tried both Azure Web Sites and Azure Cloud Services. - I saw some cloud alternatives that should work with OWIN, like Elmah.io or Raygun.io, but I don't need their cloud features and it is definitely not worth paying hundreds $ per year just to log some exceptions.
What should be the best way to log any possible exception thrown by my application?
Thanks for your help