[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.
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 :)
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!
Re: Universal StreamWriter logging updating file in real time
[DELETED] Accidental duplicate post.