Here, implementation details are important. Basically, when you write StreamWriter text, the text you write is not necessarily bound to a file on disk. Instead, it may be somewhere in the buffer, and this buffer must be cleared to be bound to disk. Periodically, this buffer will be flushed by StreamWriter itself. But if you allow your process to exit without final cleaning, uncommitted entries can still be stored in the buffer.
So, call writer.Flush , writer.Close , writer.Dispose or, best of all, wrap using StreamWriter in the using block so that it is for you.
source share