|
-
Jan 25th, 2013, 09:26 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Jan 25th, 2013, 09:37 AM
#2
Hyperactive Member
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
-
Jan 25th, 2013, 10:27 AM
#3
Thread Starter
Hyperactive Member
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!
-
Jan 25th, 2013, 10:27 AM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|