Trace listeners

Discussion in 'ASP .Net' started by martin, Dec 17, 2003.

  1. martin

    martin Guest

    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.
     
    martin, Dec 17, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rukmal Fernando
    Replies:
    4
    Views:
    871
    Richard Grimes [MVP]
    Oct 27, 2003
  2. Martin

    Trace Listeners in a web app

    Martin, May 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    601
    Rick Strahl [MVP]
    May 31, 2004
  3. msnews.microsoft.com
    Replies:
    0
    Views:
    467
    msnews.microsoft.com
    Jan 5, 2007
  4. Replies:
    0
    Views:
    682
  5. Matt Kruse
    Replies:
    2
    Views:
    180
Loading...

Share This Page