1

I have a WCF service (project output type - windows application) hosted as Windows service. All client and server logic is in c# code and I haven't any configuration files. I need to enable wcf tracing without using config file. How can I do that?

2 Answers 2

1

You can programmatically configure what you would put in your .config file. When you initialize your service just add this code (customize it according to your logging requirements):

var listener = new XmlWriterTraceListener("Log.xml");
Debug.Listeners.Add(listener);

Note that you can set all properties (log level, for example) you need as you would do with attributes in your .config file:

Debug.AutoFlush = true;
listener.TraceOutputOptions = TraceOptions.Callstack;

You may also add your custom filters:

listener.Filter = new MyCustomTraceFilter();
3
  • It should, but it needs to target TraceSource instead of Debug. Oct 8, 2014 at 15:03
  • @MatthewMartin Debug will forward (live) to TraceInternal but yes, if OP has a custom TraceSource it's what he has to use. Oct 8, 2014 at 15:08
  • The Service.Model DLL as it is running writes to a TraceSource("System.ServiceModel"), to capture that, you have to add a TraceSource of the same name to the context & add a listener to that. The Debug, Trace static methods are for the users own ad hoc tracing, which he doesn't appear to be doing. If WCF was writing to Debug, then we should see the oceans of WCF trace in the visual studio window all the time. Oct 8, 2014 at 15:12
0

By design you cannot do it see:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/25b17fef-5660-499d-ad1b-aaa3b8ab7f60/how-do-you-enable-wcf-tracing-without-using-a-config-file-programmatically?forum=wcf

You cannot do this without any config files. But you can have one system that Writes the config file for a second system. The first system would then start the second in a seperate app pool. The logging would be turned on in the second system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.