Trace listeners

M

martin

Hi,

I have created an asp.net application as a project, and also another project
that is just a class library.
My asp.net application calls a function in the class library.
I am attempting to place instrumentation inside the function of my class
library to write to a text file, I am using an TextWriterTraceListener
object..

The problem is that I can write to the trace listener with the following
code, but only once

' Creates the text file that the trace listener will write to.
Dim myTraceLog As New System.IO.FileStream("C:\myTraceLog.txt",
IO.FileMode.Append)
' Creates the new trace listener
Dim myListener As New TextWriterTraceListener(myTraceLog)
Trace.Listeners.Add(myListener)
myListener.WriteLine("Called IsSecureUser Function")
Trace.Flush()
myListener.Flush()

The class function (above) is called from a button click event. The first
time the button is pressed then no problem.
If the button is clicked again then I get an error saying "The process
cannot access the file "C:\myTraceLog.txt" because it is being used by
another process."

if I close the file at the end of the function I get the error "Cannot
access a closed file."

and if I close the trace listener I get "Cannot write to a closed
TextWriter." the first time that I press the button.

could anybody please tell me how I re use the trace listener over and over
again without the error.

thank you in advance.

cheers

martin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top