I've managed to hook up SharpRaven to log and capture errors successfully from both MVC and Web API controllers, but have been unable to log and capture 404 errors.
I'm attempting to do this through Application_Error
like so:
public class MvcApplication : System.Web.HttpApplication
{
RavenClient _RavenClient;
protected void Application_Start()
{
_RavenClient = new RavenClient(ConfigurationManager.AppSettings["RavenClient:DNS"]);
...
}
protected void Application_Error(object sender, EventArgs e)
{
_RavenClient.Capture(new SentryEvent(Server.GetLastError()));
}
}
If I set a break point on the _RavenClient.Capture(...)
I can see the error getting captured, but the 404 errors captured here never turn up in https://sentry.io/
This is also true for non-404 exceptions that hit this line of code, if I disable the other controller integrations.
Any ideas why this isn't working fully? Is there a better way I could be doing this that might have a better chance at working?
Everything works as desired if I create the RavenClient
when I need it within the Application_Error
method itself. Seems there must be a problem with creating the client in Application_Start
and then using it later.
This is my modified working code:
protected void Application_Error(object sender, EventArgs e)
{
new RavenClient(ConfigurationManager.AppSettings["RavenClient:DNS"])
.Capture(new SentryEvent(Server.GetLastError()));
}