Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

WCF Tracing


I recently read a blog entry about WCF Tracing logging through smartinspect. However, i need to route the specified entries to a file rather than directly to the console. I tried to use the initializeData attribute of the Listener, but it didn’t work. The configuration i use is the following:





The first listener works ok.

Thank you in advance.



We don’t use the initializeData attribute to configure SmartInspect here. The listener actually directly uses SiAuto, so you use SmartInspect’s normal configuration system. I.e. either use the Connections attribute to configure file logging or use a configuration file:

SiAuto.Si.Connections = "file(filename=c:\\log.sil)";
SiAuto.Si.Enabled = true;

I hope this helps!




I know all about the configuration system. The problem is that i need to direct WCF tracing info to its own, different file. I really don’t want this kind of information to interfere with the logging entries of my application.

I thought about using more than one Connection, but i cannot seem to find a way to filter only the WCF entries.


Thanks for the additional details, that makes sense. In this case, you would need to create the trace listener at run-time instead of specifying it in the configuration file. When you create the trace listener at run-time, you can pass the SmartInspect session the trace listener should use for logging.

So would basically do the following:

  • Create a new SmartInspect instance and configure it
  • Add a new session for the SmartInspect instance
  • Create an instance of the SmartInspect trace listener and pass the session to the constructor
  • Register the trace listener via System.Diagnostics.Trace.Listeners.Add

Please also take a look at the following article with some background information about SmartInspect’s trace listener:

Let me know in case you have further questions about this.




There is a big problem with the implementation you suggest. The created listener, needs to get registered to the special WCF Trace Source with the name “System.ServiceModel” which is responsible for the WCF tracing and not a general Trace Source ('m not the one that generates WCF logging info…). The Trace Source used by the WCF engine, is so special, which is marked Internal and so there is no way for the developer to programmatically obtain a reference to it and manipulate its collection of Listeners (other than playing with Reflection and dangerously inspect the Microsoft libraries for the proper class…). This effectively means, that there is no way to accomplish WCF logging in any other way than through the configuration file. And this means, that you need to implement something different or else your notion of “SmartInspect support WCF logging messages” is rather exaggerated.



An alternative way to not use SmartInspect’s default configuration for WCF logging would be to use your own trace listener class. SmartInspect’s trace listener has less than 100 lines of code without comments and you could simply use your own class that doesn’t use SiAuto.

You can find SmartInspect’s implementation in your SmartInspect installation directory under source\dotnet\debugtrace\Gurock\SmartInspect\DebugTrace. After copying and adjusting the class to use your own SmartInspect and Session instances, you can simply compile it into your main application assembly or use a dedicated assembly for this class.

I hope this helps.



I took a look at the code and apparently a custom solution through tweaking the default constructor is rather easy. Nevertheless, i really don’t want to get in the trouble maintaining a separate version of this class. It doesn’t provide something more elaborate than the Microsoft implementation though svclog files.

Thanks for your time.



I agree that there isn’t a big advantage over .NET’s built solution if you don’t plan to include the WCF logging data in your standard SmartInspect log files/protocols etc. Let me know if there’s anything else we can help with.