By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,761 Members | 1,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,761 IT Pros & Developers. It's quick & easy.

Trace listeners

P: n/a
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.
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.