Web.API not reporting exception
EasterMike
Posted on
Mar 15 2014
I am new to raygun and and I am adding to a Web.API project. I followed the instructions for ASP.NET by adding a module to the system.webServer section in web.config.
I was not able to see any errors that I generated in the dashboard.
I think added the code to an ExceptionFilterAttribute and added the filter to the HttpConfiguration filters in the WebApiConfig.cs file.
The code I added was:
var exception = context.Exception;
new RaygunClient().Send(exception);
After I did this it worked.
Is there something I am missing in order to get the exception reporting to work with the http module?
John-Daniel Trask
Raygun
Posted on
Mar 15 2014
Hi Mike,
Sorry to hear about the issue here. Indeed there is a shortcoming with the WebAPI as it wraps up and handles errors in its own way. We'll look to better document this and investigate if there's a way we could still automatically hook in without needing much more work.
Glad you got it sorted. Let me know if we could help with anything else!
John-Daniel Trask
Co-founder
Mindscape Limited
EasterMike
Posted on
Mar 16 2014
Did I sort it out??
Is the proper way to integrate to use the two lines of code to send an exception to raygun?
This seems reasonable and not complicated but I want to make sure I am integrating the proper way.
Thanks, Mike
martin308
Posted on
Mar 17 2014
Hi Mike,
There is a community provider for WebAPI which you can view here, hopefully this is helpful
christensena
Posted on
Mar 19 2014
I've just started integrating and found the same problem in my testing. Given the slickness of the rest of raygun I was a little surprised to say the least.
christensena
Posted on
Mar 19 2014
My interim solution:
public class RaygunWebApiExceptionLogger : IExceptionLogger
{
public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
new RaygunClient().Send(context.Exception);
return Task.FromResult(false);
}
}
and in the application setup
GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new RaygunWebApiExceptionLogger());
christensena
Posted on
Mar 19 2014
OK after checking that Send() is not async I've revised it to this:
public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
var raygunClient = new RaygunClient();
return Task.Factory.StartNew(() => raygunClient.Send(context.Exception));
}