From f46653ed9e6fa29626fdd486d04663044c98bfc5 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 22 Jan 2018 12:03:08 +0000 Subject: [PATCH] logger: Keep a StreamWriter open to log, instead of opening+closing all the time --- Sparkles/Logger.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Sparkles/Logger.cs b/Sparkles/Logger.cs index 3db3979c..f6a4c896 100644 --- a/Sparkles/Logger.cs +++ b/Sparkles/Logger.cs @@ -22,8 +22,8 @@ namespace Sparkles { public static class Logger { - static object debug_lock = new object (); - static int log_size; + static StreamWriter log_writer = File.AppendText (Configuration.DefaultConfiguration.LogFilePath); + static object log_writer_lock = new object (); public static void LogInfo (string type, string message) @@ -48,15 +48,9 @@ namespace Sparkles { if (Configuration.DebugMode) Console.WriteLine (line); - lock (debug_lock) { - if (log_size >= 1000) { - File.WriteAllText (Configuration.DefaultConfiguration.LogFilePath, line + Environment.NewLine); - log_size = 0; - - } else { - File.AppendAllText (Configuration.DefaultConfiguration.LogFilePath, line + Environment.NewLine); - log_size++; - } + lock (log_writer_lock) { + log_writer.WriteLine (line); + log_writer.Flush (); } }