mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-03 22:13:10 +00:00
Faster binary-process log writing
This commit is contained in:
parent
413a46c761
commit
1e035d6a68
@ -35,6 +35,21 @@ namespace Logging
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteRawMany(IEnumerable<string> 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)}]";
|
||||
|
||||
@ -9,7 +9,7 @@ namespace CodexPlugin
|
||||
private readonly LogFile logFile;
|
||||
private readonly Process process;
|
||||
private readonly CodexProcessConfig config;
|
||||
private readonly List<string> logBuffer = new List<string>();
|
||||
private List<string> logBuffer = new List<string>();
|
||||
private readonly object bufferLock = new object();
|
||||
private readonly List<Task> streamTasks = new List<Task>();
|
||||
private bool running;
|
||||
@ -47,14 +47,14 @@ namespace CodexPlugin
|
||||
{
|
||||
if (logBuffer.Count > 0)
|
||||
{
|
||||
var lines = Array.Empty<string>();
|
||||
List<string> lines = null!;
|
||||
lock (bufferLock)
|
||||
{
|
||||
lines = logBuffer.ToArray();
|
||||
logBuffer.Clear();
|
||||
lines = logBuffer;
|
||||
logBuffer = new List<string>();
|
||||
}
|
||||
|
||||
foreach (var l in lines) logFile.WriteRaw(l);
|
||||
logFile.WriteRawMany(lines);
|
||||
}
|
||||
else Thread.Sleep(100);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user