I can enable tracing by replacing the default No Op trace writer.
GlobalConfiguration.Configuration.Services.Replace(typeof(ITraceWriter), new SimpleTracer());
But how can I disable (and enable it again) while the server is running?
The Enum “TraceLevel” has the option TraceLevel.Off.
Is there a way to set the tracing-framwork form web api to TraceLevel.Off?
Take a look at this article here.
And
In short if you want to enable and disable your tracing or chose not to log a trace for a particular level it is up to you to implement inside your
SimpleTracer.You could create your own threadsafe singleton TraceConfiguration (akin to GlobalConfiguration) implementation to control the trace configuration to allow toggling on or off within the code.
Or you could set and access properties on the request object to determine whether to enable tracing or not. This could be set by ActionFilters on actions and controllers or even set within the controller.
Or as the article suggests if you are using NLog or Log4Net etc it is up to you set the levels enabled via config etc.