Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing to one trace file from Web Service

Wilfried Hoermann
Guest
 
Posts: n/a
#1: Nov 11 '05
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]
Guest
 
Posts: n/a
#2: Nov 11 '05

re: Writing to one trace file from Web Service


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

"Wilfried Hoermann" <nnamroeh@nowhere.com> wrote in message
news:0fee01c38cb7$dd461f90$a101280a@phx.gbl...[color=blue]
> 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();
> }[/color]


Wilfried Hoermann
Guest
 
Posts: n/a
#3: Nov 11 '05

re: Writing to one trace file from Web Service


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.

How could I achieve this?
Closed Thread


Similar .NET Framework bytes