Programmatically enable trace debug for a page

Is there a way to enable the trace output programmatically? For example in the
web.config under I have:
<trace enabled="true" localOnly="true" pageOutput="true" />

but then I would like the code to decide at runtime (by a variable in the URL
query string or something) if debug tracing output should be displayed for that
page (similar to localOnly="false"). Any suggestions?