Enabling Logging Dynamically
You can use your configuration file to enable and disable logging dynamically. Using the example configuration file from the earlier page, your code needs only to test the value of logging in the configuration file. For example, in your code that initializes the connection you would enable logging with the following code:
private void InitConnection()
{
...
if (ConfigurationManager.AppSettings.Get("logging").Equals("yes"))
{
cacheConnectStr +=
";LogFile = " + ConfigurationManager.AppSettings.Get("logfile");
}
...
}