namespace MSCO.Server; /// Die letzten Log-Zeilen im Speicher - für die Live-Konsole im Web-Panel. public static class LogBuffer { public readonly record struct Line(long Seq, string Time, string Text); const int Capacity = 3000; static readonly Queue 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(); } } /// Zeilen nach der angegebenen Nummer (höchstens max, die neuesten). public static List 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; } } }