Sat
Sat

Reputation: 133

How to enable WCF traces programmatically?

Is there a way to enable/disable the WCF trace/logging for a perticular end point without changing the web.config ?

Upvotes: 5

Views: 2581

Answers (1)

The other other Alan
The other other Alan

Reputation: 1908

You first need to access the trace object by name, as its defined in the .config file. For example:

TraceSource ts = new TraceSource("System.ServiceModel");

Then you can set the filter level to all, none or anything in between:

ts.Switch.Level = SourceLevels.Off;   // nothing
ts.Switch.Level = SourceLevels.All;   // everything
ts.Switch.Level = SourceLevels.Warning;   //warning or higher

BTW - the TraceSource class is in the System.Diagnostics namespace, so don't forget the appropriate using statement.

Upvotes: 2

Related Questions