diff --git a/Framework/Logging/LogFile.cs b/Framework/Logging/LogFile.cs index f9147ce9..2ec94be0 100644 --- a/Framework/Logging/LogFile.cs +++ b/Framework/Logging/LogFile.cs @@ -35,6 +35,21 @@ namespace Logging } } + public void WriteRawMany(IEnumerable lines) + { + try + { + lock (fileLock) + { + File.AppendAllLines(Filename, lines); + } + } + catch (Exception ex) + { + Console.WriteLine("Writing to log has failed: " + ex); + } + } + private static string GetTimestamp() { return $"[{Time.FormatTimestamp(DateTime.UtcNow)}]"; diff --git a/ProjectPlugins/CodexPlugin/BinaryProcessControl.cs b/ProjectPlugins/CodexPlugin/BinaryProcessControl.cs index de8a75c2..c4ed3ee1 100644 --- a/ProjectPlugins/CodexPlugin/BinaryProcessControl.cs +++ b/ProjectPlugins/CodexPlugin/BinaryProcessControl.cs @@ -9,7 +9,7 @@ namespace CodexPlugin private readonly LogFile logFile; private readonly Process process; private readonly CodexProcessConfig config; - private readonly List logBuffer = new List(); + private List logBuffer = new List(); private readonly object bufferLock = new object(); private readonly List streamTasks = new List(); private bool running; @@ -47,14 +47,14 @@ namespace CodexPlugin { if (logBuffer.Count > 0) { - var lines = Array.Empty(); + List lines = null!; lock (bufferLock) { - lines = logBuffer.ToArray(); - logBuffer.Clear(); + lines = logBuffer; + logBuffer = new List(); } - foreach (var l in lines) logFile.WriteRaw(l); + logFile.WriteRawMany(lines); } else Thread.Sleep(100); }