I have some code from my VB.NET 1.1 days that allowed me to dynamically check if Debug was enabled in web.config. I figured why re-invent the wheel in turning on/off logging if I could simply have the web administrator enable debug. Here is the code I used in VB.NET that worked just fine:
This property actually looks at the web.config configuration setting. If you look at it using Reflector you will find that it gets the actual ConfigurationSection object using some internal classes.