[英]How to enable WCF traces programmatically?
有没有办法在不更改web.config的情况下为特定端点启用/禁用WCF跟踪/日志记录?
You first need to access the trace object by name, as its defined in the .config file. 首先需要按名称访问跟踪对象,如.config文件中定义的那样。 For example:
例如:
TraceSource ts = new TraceSource("System.ServiceModel");
Then you can set the filter level to all, none or anything in between: 然后,您可以将过滤级别设置为all,none或之间的任何内容:
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. BTW -
TraceSource
类位于System.Diagnostics
命名空间中,因此不要忘记相应的using
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.