parush / elmah

Automatically exported from code.google.com/p/elmah
0 stars 0 forks source link

Disabling modules via configuration #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
One of the additions I made to your product was the addition of 
an 'Enabled' attribute when adding httpModules that handle the errors.

This makes it very easy to turn on/off email notifications and such.  I 
was hoping you might make this change in the shipping code (or add support 
for this 'enabled' property to a base class).

The code is a very easy  change.  In each handler class (like SqlErrorLog 
and ErrorMailModule) you make the following change:

add this to class declaration:
private bool _enabled;

add this to the Init() (like in ErrorMailModule) or constructor (like in 
SqlErrorLog):

//Init() code...
_enabled = Convert.ToBoolean(GetSetting(config, "enabled", 
bool.TrueString)); //WB

//Constructor code
string enabled = (string)config["enabled"]; //WB
if (string.IsNullOrEmpty(enabled)) //WB
    _enabled = true; //WB
else //WB
    _enabled = Convert.ToBoolean(enabled); //WB

Finally, disable handler if appropriate.  For ErrorMailModule, you put 
this in the Init() after setting the _enabled from above:
if (_enabled)
    application.Error += new EventHandler(OnError);

For SqlErrorLog, you put this in the override of Log():
if (!_enabled)
   return;

Original issue reported on code.google.com by wayne.br...@gmail.com on 26 Jun 2007 at 3:53

GoogleCodeExporter commented 9 years ago
How is this different than simply commenting out the relevant sections/elements 
in 
the configuration file to disable the functionality? What is the major benefit 
of 
being able to leave a component in the pipeline yet have it disabled? Granted 
it's 
easy to add, but still, it would be nice to understand the strong case for this 
overload.

Original comment by azizatif on 26 Jun 2007 at 7:30

GoogleCodeExporter commented 9 years ago
I just like to be able to enable/disable things via configuration attributes 
instead 
of the comment out. It was easy to add and I like to do that as opposed to 
commenting them out if possible....

Either way....

Original comment by wayne.br...@gmail.com on 26 Jun 2007 at 6:32

GoogleCodeExporter commented 9 years ago

Original comment by azizatif on 14 Nov 2007 at 10:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I would also like to see this.

Personally, I use a custom utility to automatically generate multiple 
web.config files from a single template and this is a feature I have wanted for 
some time now as I cannot comment out a line with my tool, but I can change a 
property value to true/false.

Original comment by laka...@gmail.com on 26 Aug 2010 at 5:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'd like this as well. 

Another solution would be to just allow an empty string for the "to" field in 
the configuration. I see that the code supports that (if the string is empty, 
it just returns out of the method. Right now it throws an exception if the 
field is empty.

Our situation is that we have multiple environments. We don't want to send 
emails in certain envrionments or from developer machines, but it's nice if the 
configuration files are mostly the same. In some projects I've been on, 
including this one, the various config files are managed with scripts and if 
they are very different then it gets weird. 

Thanks very much for a great tool.

Original comment by daleks...@signaleleven.com on 6 Jun 2014 at 7:17

GoogleCodeExporter commented 9 years ago
This issue has been migrated to:
https://github.com/elmah/Elmah/issues/9
The conversation continues there.
DO NOT post any further comments to the issue tracker on Google Code as it is 
shutting down.
You can also just subscribe to the issue on GitHub to receive notifications of 
any further development.

Original comment by azizatif on 25 Aug 2015 at 8:15