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?
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();
By design you cannot do it see:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.