开发者

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, an开发者_开发技巧d 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.


Link to the original bug/feature in google code.

Link to a google groups discussion giving basic sample code for implementing the service container.

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; 
  } 
} 


I think you can do that using version 1.2 beta http://code.google.com/p/elmah/issues/list?&q=label%3AMilestone-Release1.2+status=Fixed&can=1


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜