Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 278
Brian Vallelunga Avatar asked Oct 26 '22 12:10

Brian Vallelunga


2 Answers

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; 
  } 
} 
like image 148
yzorg Avatar answered Dec 01 '22 04:12

yzorg


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

like image 34
Ahmed Magdy Avatar answered Dec 01 '22 03:12

Ahmed Magdy