c# - Keep file open, but don't lose data on crash -


I have a group of log files in my app I am using stream Reuters to populate those .

The code looks like this:

  try {lock (fileLock) {(var sw = new streamwriter (GetTmpFileName (target)), true)) {sw.WriteLine ( User.UserName); }}} Hold (exception e) {Console.WriteLine (e); }  

Obviously, from many points, this is a bad idea. But for me, it is important not to loose the data when the application crashes.

Can someone recommend me a better way of doing this?


Comments