c# - Keep the file open, don't lose data when the app crashes -
i need log info file around 1000-2000 times minute. need save info in case app crashes.
currently here's i'm doing:
using(streamwriter sw=new streamwriter(filename,true)) { sw.writeline(info); }
this works, it's extremely slow.
i'd doing this:
static streamwriter sw=new streamwriter(file,true); .... public static void main(...) { ..... sw.writeline(....); }
but when write code this, i'm afraid info store lost when app crashes.
what can preserve info in file without having open , close time?
you can call streamwriter.flush()
after each write.
public static void main(...) { ..... sw.writeline(....); sw.flush(); }
Comments
Post a Comment