Despite spending hours searching the net, I could not find a solution to this problem. Being a noob for Web API v2, this is probably a very simple question for someone who has more experience.
I have a clean MVC project updated to use Web API v2. I installed several ELMAH packages through Nuget.
When working with a regular home controller in MVC, if I put the wrong page, for example. / Home / test will generate 404. Elmah, in turn, fixes this, and I only know from the logs which pages may be damaged, etc.
I want to pass this registration level to an API controller. Logging does work, but I have to throw an exception from the controller to get something registered with Elmah.
I assume that things like 404/415 errors are classified as "processed" exceptions, but I only get processed exceptions without registering.
Anyway, I want ANY errors on the API controller to be logged. This way, I can control how the API is used, and any errors caused by client calls. Errors can be 404s, 415 for unsupported data types and so on. That way, if there is any problem with the hosted data from the client, I can easily see the response that would be returned.
Thanks in advance!
WebApi.config:
Public static void Register(HttpConfiguration config)
{
...
config.filters.add(new Elmah.Contrib.WebApi.ElmahHandleErrorApiAttribute());
}
Filter.config:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new Elmah.Contrib.Mvc.ElmahHandleErrorAttribute());
filters.Add(new HandleErrorAttribute();
}