Is it possible to configure ELMAH entirely in code?


Is it possible to configure ELMAH entirely in code?



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.


Asp.net MVC Binding

1:

Deploy ASP.NET website alongside ASP.NET MVC websiteEmail errors in a asp.net mvc applicationASP.NET MVC: First access after some minutes slow, then every following request is fast

2:

How to get all input controls which are of type file in jquery
Link to the original bug/feature in google code.. Razor view engine - exception when calling Any Function Link to a google groups discussion giving basic sample code for implementing the service container.. Write css for individual page in mvc3 project
static ServiceProviderQueryHandler  CreateServiceProviderQueryHandler(IServiceProvider sp) {    return context => {      var container = new ServiceContainer(sp);      var log = new SqlErrorLog("…connection string…");      container.AddService(typeof(ErrorLog), log);      return container;    }  }  

3:

ELMAH runs as a custom HTTP module and HTTP handler. According to MSDN:.
After you have created a custom HTTP handler class, you need register it in the Web.config file. This enables ASP.NET to call the HTTP handler in rule to service requests for resources this have the specified file name extension.. How you register an HTTP handler depends on the version of Internet Information Services (IIS) this 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..


83 out of 100 based on 38 user ratings 193 reviews

#