Results 1 to 4 of 4

Thread: [RESOLVED] Universal StreamWriter logging updating file in real time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Resolved [RESOLVED] Universal StreamWriter logging updating file in real time

    I have created a Logging class which inside hosts 4 static methods of writing to a text file: BeginLog, Log, EndLog, and SendLog. Right now these all use the same class level defined StreamWriter variable. I initially did this so I wouldn't have to constantly create new ones and keep checking if ones are open/closed/etc... However, I noticed that changes won't be saved in the text file until the StreamWriter is closed/disposed.

    I tried wrapping each one in a using block, but kept getting constant errors because so many places call writing to the log that it eventually tries writing to a closed stream...

    Any ideas on how the best implementation for this would be, so that the log basically gets 'saved' after each write without worrying about how many writes are occuring.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: Universal StreamWriter logging updating file in real time

    I do believe that is what the .Flush method is used for on the stream writer. I haven't used it myself, but give it a shot and let us know

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: Universal StreamWriter logging updating file in real time

    Wow, how have I not known about that...

    Guess I've been spoiled by always wrapping IDisposable stuff in using blocks. Works great, thanks a million!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    Re: Universal StreamWriter logging updating file in real time

    [DELETED] Accidental duplicate post.

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