ExceptionLoggerHttpModule and Exception Policy

Jun 22, 2007 at 11:51 AM
This module seems to only work with a fixed policy name i.e. GlobalExceptionLogger, is this correct?
Jun 23, 2007 at 2:47 AM
Yep. Here is all the code. You can see the reference to the GlobalExceptionLogger at the end.

You can easily write your own that references a different name, but you just need to make sure you also modify the web.config file with the new policy name.

    public class ExceptionLogger : IHttpModule
    {
        public void Dispose()
        {
        }
 
        public void Init(HttpApplication context)
        {
            if (!Debugger.IsAttached)
            {
                context.Error += new EventHandler(OnUnhandledException);
            }
        }
 
        protected virtual void OnUnhandledException(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            Exception ex = application.Server.GetLastError().GetBaseException();
            ExceptionPolicy.HandleException(ex, "GlobalExceptionLogger");
        }
    }

Regards,

Dave

______________________________

David Hayden
Microsoft MVP C#