views:

61

answers:

1

I'd like to configure ELMAH for an ASP.NET MVC site entirely in code. This includes registering the module, setting the logging provider and settings, and filtering exceptions.

The only part I've managed to do so far is filter exceptions. Has anyone else figured out how to do this? I'd really like to avoid cluttering up my config file with settings that won't ever change.

A: 

ELMAH runs as a custom HTTP module and HTTP handler. According to MSDN:

After you have created a custom HTTP handler class, you must register it in the Web.config file. This enables ASP.NET to call the HTTP handler in order to service requests for resources that have the specified file name extension.

How you register an HTTP handler depends on the version of Internet Information Services (IIS) that hosts your application. For IIS 6.0, you register the handler by using the httpHandlers section of the Web.config file. For IIS 7.0 running in Classic mode, you register the handler in the httpHandlers section, and you map the handler to the Aspnet_isapi.dll file. For IIS 7.0 running in Integrated mode, you register the handler by using the handlers element in the system.WebServer section.

Rick Strahl has a blog post where he programmatically registers an HttpModule. I suppose it might be possible to use a similar technique with ELMAH.

Eric King