Results 1 to 3 of 3

Thread: TextWriter locking files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    90

    TextWriter locking files

    I have an ASP.Net project where I have taken all of the error logging and created a new VB.Net logging class.
    In the ASP.net project I have a reference to the new VB.Net logging class.
    I have a try catch block, in the catch I create a logging object and call the logging from there. This all works great.

    The problem I am having is that after the first log is written, the log file is locked. The code for logging is the exact same as before (and it worked like a charm when it was in the same ASP.Net project). Now that it is a Class that is reference to, it some how keeps a lock on the file. Any ideas?

    Sample code from Logging class where it opens the file and writes the text:


    Dim FileWriter As TextWriter = File.AppendText(oLoggingProperties.LoggingFileName & ".txt")

    FileWriter.WriteLine(sLevel & " Error Log " & Date.Now & " From Class - " & sClass & " Method - " & sMethod)

    FileWriter.WriteLine(oException.Message)
    FileWriter.WriteLine(oException.Source)
    FileWriter.WriteLine(oException.StackTrace)
    FileWriter.WriteLine(oException.TargetSite)
    FileWriter.WriteLine("")
    FileWriter.Close()

    Sample code from the WebForm1.aspx.vb code behind file:
    Try
    ... some code .....

    Catch oException As Exception
    Dim lLogging As Logging.Logging = New Logging.Logging()
    lLogging.Log(oException, "Login", "btnLogin_Click", "Fatel")
    Err.Clear()
    End Try


    Any ideas of how to make sure the file is closed?

    Thanks

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Try this...
    Code:
    Dim lLogging As Logging.Logging = New Logging.Logging()
    lLogging.Log(oException, "Login", "btnLogin_Click", "Fatel")
    Err.Clear()
    lLogging.Dispose()
    I am not thinking well tonight, so that might not work, but worth a try.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    90
    I did some research in the Help for .Net Framework. It says to ONLY implement the Dispose method through the IDisposable interface when you have Unmanaged code. How can I tell what is manageed and unmanaged? Is there some kind of grid that will tell me this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width