We have an HttpModule that is designed to catch exceptions and log them to the db. It looks something like this:
public class ExceptionLoggingModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.Error += OnError;
}
private static void OnError(object sender, EventArgs e)
{
try
{
var context = (HttpApplication) sender;
var exception = context.Server.GetLastError();
if (exception != null)
{
// Log exception
}
}
catch(Exception)
{
}
}
}
This works in general, but I've just noticed that the OnError method never fires when an error occurs within Page Methods (i.e. methods in a code behind file marked with the WebMethod attribute).
How come?
Is there something I can do about this, other than reimplementing the exception logging inside the Page Method itself?