Groups | Blog | Home
all groups > dotnet xml > october 2003 >

dotnet xml : Writing to one trace file from Web Service


Wilfried Hoermann
10/7/2003 2:46:21 AM
Presumably a trivial question...
I want to write trace information from a web service to a
log file using the Trace Class. Is this possible without
closing and opening the Trace in every single web method?

Code:
public Webservice()
System.IO.FileStream ts = new
System.IO.FileStream(traceFile,System.IO.FileMode.Append);
Trace.Listeners.Remove
(Trace.Listeners[0]);
Trace.Listeners.Add(new
TextWriterTraceListener(ts));
Trace.WriteLine("Constructor " +
System.DateTime.Now.ToString());
Trace.Close();

[WebMethod]
public WebMethod ()
{
System.IO.FileStream ts = new
System.IO.FileStream(traceFile,System.IO.FileMode.Append);
Trace.Listeners.Remove
(Trace.Listeners[0]);
Trace.Listeners.Add(new
TextWriterTraceListener(ts));
Trace.WriteLine("Method " +
System.DateTime.Now.ToString());
Trace.Close();
Dino Chiesa [Microsoft]
10/9/2003 1:49:52 PM
Maybe you need to add the relevant objects to application state or session
state or whatever is appropriate.
Then when a web method is invoked, retrieve the objects and use them.

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

[quoted text, click to view]

Wilfried Hoermann
10/15/2003 12:57:19 AM
Maybe you could be a little bit more specific.

I have got a File(stream) and the Trace Utility Class with
the TraceListeners Collection.
I want to add the File to the TraceListeners and write
Trace output from various Webmethods to it.

AddThis Social Bookmark Button