Using a configuration file I want to enable myself to turn on and off things like (third party) logging and using a cache in a C# website. The solution should not be restricted to logging and caching in particular but more general, so I can use it for other things as well.
I have a configuration xml file in which I can assert that logging and caching should be turned on or off (it could also be in the Web.Config, that's not the point right now) which will result in for example a bool logging
and a bool caching
that are true
or false
.
The question is about this part:
What I can do is prepend every logging/caching related statement with if (logging)
and if (caching)
.
What is better way of programming this? Is there also a programming term for this kind of problem? Maybe attributes are also a way to go?