Files

34 lines
1022 B
C#

namespace MSCO.Server;
/// <summary>Die letzten Log-Zeilen im Speicher - für die Live-Konsole im Web-Panel.</summary>
public static class LogBuffer
{
public readonly record struct Line(long Seq, string Time, string Text);
const int Capacity = 3000;
static readonly Queue<Line> lines = new();
static readonly object gate = new();
static long seq;
public static long LastSeq { get { lock (gate) return seq; } }
public static void Add(string time, string text)
{
lock (gate)
{
lines.Enqueue(new Line(++seq, time, text));
while (lines.Count > Capacity) lines.Dequeue();
}
}
/// <summary>Zeilen nach der angegebenen Nummer (höchstens max, die neuesten).</summary>
public static List<Line> Since(long after, int max)
{
lock (gate)
{
var result = lines.Where(l => l.Seq > after).ToList();
return result.Count > max ? result.GetRange(result.Count - max, max) : result;
}
}
}