This commit is contained in:
EonaCat authored and Jeroen Saey committed 2026-09-25 15:13:02 +02:00
1 parent 17d7426b44
commit a0959ea2c7
11 files changed
+171 -35

No files matched your search

+31 -1
View File
@@ -86,6 +86,7 @@ namespace EonaCat.LogStack.LogClient
entry.Properties = JsonHelper.ToJson(properties);
_logQueue.Enqueue(entry);
TrimQueue();
if (_logQueue.Count >= _options.BatchSize)
{
@@ -93,6 +94,22 @@ namespace EonaCat.LogStack.LogClient
}
}
/// <summary>
/// Drops the oldest entries once the queue exceeds the configured maximum size,
/// so a server outage cannot grow the queue without bound.
/// </summary>
private void TrimQueue()
{
while (_logQueue.Count > _options.MaxQueueSize && _logQueue.TryDequeue(out _))
{
}
}
private bool IsExpired(LogEntry entry)
{
return DateTime.UtcNow - entry.Timestamp > _options.MaxRetention;
}
private async Task FlushAsync()
{
if (_logQueue.IsEmpty)
@@ -106,6 +123,12 @@ namespace EonaCat.LogStack.LogClient
var batch = new List<LogEntry>();
while (batch.Count < _options.BatchSize && _logQueue.TryDequeue(out var entry))
{
// Drop stale entries instead of holding/sending them indefinitely.
if (IsExpired(entry))
{
continue;
}
batch.Add(entry);
}
@@ -155,10 +178,17 @@ namespace EonaCat.LogStack.LogClient
Console.WriteLine($"[LogCentral] Failed to send logs to EonaCat: {ex.Message}");
}
// Only hold onto entries that are still within the retention window;
// never retry/re-queue indefinitely, and never exceed the max queue size.
foreach (var entry in batch)
{
_logQueue.Enqueue(entry);
if (!IsExpired(entry))
{
_logQueue.Enqueue(entry);
}
}
TrimQueue();
}
}