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(); } 

but should use nlog or log4net!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -