Adding messages to trace log in WCF service?
If I have trace logging enabled on a WCF 开发者_JS百科service is it possible to write custom messages to it? If so how? If I don't have trace logging enabled will it just not write or will it throw an exception?
You can use below code:
FileStream traceLog = new FileStream("C:\\log\\Traces.svclog",FileMode.OpenOrCreate);
TextWriterTraceListener myListener = new TextWriterTraceListener(traceLog);
Trace.Listeners.Add(myListener);
myListener.WriteLine("Sending trace information");
Trace.Flush();
myListener.Flush();
精彩评论