Enabling and disabling logs from the code

I need to enable and disable log from the code. I also need to change the “switchValue” from the code.

I have read the topic
https://componentspace.com/Forums/17/Enabing-SAML-Trace?PageIndex=1

Is this possible?

We use the standard ASP.NET system diagnostics for logging.
I’m not aware of any way to toggle logging on or off other than by updating the web.config.