Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable WCF traces programmatically?

Tags:

wcf

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

like image 625
Sat Avatar asked Nov 01 '22 16:11

Sat


1 Answers

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.

like image 186
AFischbein Avatar answered Nov 08 '22 05:11

AFischbein