logger: Keep a StreamWriter open to log, instead of opening+closing all the time
This commit is contained in:
parent
4426b8cd8f
commit
f46653ed9e
|
@ -22,8 +22,8 @@ namespace Sparkles {
|
||||||
|
|
||||||
public static class Logger {
|
public static class Logger {
|
||||||
|
|
||||||
static object debug_lock = new object ();
|
static StreamWriter log_writer = File.AppendText (Configuration.DefaultConfiguration.LogFilePath);
|
||||||
static int log_size;
|
static object log_writer_lock = new object ();
|
||||||
|
|
||||||
|
|
||||||
public static void LogInfo (string type, string message)
|
public static void LogInfo (string type, string message)
|
||||||
|
@ -48,15 +48,9 @@ namespace Sparkles {
|
||||||
if (Configuration.DebugMode)
|
if (Configuration.DebugMode)
|
||||||
Console.WriteLine (line);
|
Console.WriteLine (line);
|
||||||
|
|
||||||
lock (debug_lock) {
|
lock (log_writer_lock) {
|
||||||
if (log_size >= 1000) {
|
log_writer.WriteLine (line);
|
||||||
File.WriteAllText (Configuration.DefaultConfiguration.LogFilePath, line + Environment.NewLine);
|
log_writer.Flush ();
|
||||||
log_size = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
File.AppendAllText (Configuration.DefaultConfiguration.LogFilePath, line + Environment.NewLine);
|
|
||||||
log_size++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue