Replaced BufferedLogEvent with LogEventRequest object

This commit is contained in:
Thorsten Sommer 2026-01-13 18:24:39 +01:00
parent 6336c95959
commit f577550262
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -1,5 +1,6 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using AIStudio.Tools.Rust;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@ -14,7 +15,7 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
private static RustService? RUST_SERVICE; private static RustService? RUST_SERVICE;
// Buffer for early log events before RustService is available // Buffer for early log events before RustService is available
private static readonly ConcurrentQueue<BufferedLogEvent> EARLY_LOG_BUFFER = new(); private static readonly ConcurrentQueue<LogEventRequest> EARLY_LOG_BUFFER = new();
// ANSI color codes for log levels // ANSI color codes for log levels
private const string ANSI_RESET = "\x1b[0m"; private const string ANSI_RESET = "\x1b[0m";
@ -36,10 +37,10 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
{ {
service.LogEvent( service.LogEvent(
bufferedEvent.Timestamp, bufferedEvent.Timestamp,
bufferedEvent.LogLevel, bufferedEvent.Level,
bufferedEvent.Category, bufferedEvent.Category,
bufferedEvent.Message, bufferedEvent.Message,
bufferedEvent.ExceptionMessage, bufferedEvent.Exception,
bufferedEvent.StackTrace bufferedEvent.StackTrace
); );
} }
@ -77,22 +78,10 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
else else
{ {
// Buffer early log events until RustService is available // Buffer early log events until RustService is available
EARLY_LOG_BUFFER.Enqueue(new BufferedLogEvent(timestamp, logLevel, category, message, exceptionMessage, stackTrace)); EARLY_LOG_BUFFER.Enqueue(new LogEventRequest(timestamp, logLevel, category, message, exceptionMessage, stackTrace));
} }
} }
/// <summary>
/// Represents a buffered log event for early logging before RustService is available.
/// </summary>
private readonly record struct BufferedLogEvent(
string Timestamp,
string LogLevel,
string Category,
string Message,
string? ExceptionMessage,
string? StackTrace
);
private static string GetColorForLogLevel(LogLevel logLevel) => logLevel switch private static string GetColorForLogLevel(LogLevel logLevel) => logLevel switch
{ {
LogLevel.Trace => ANSI_GRAY, LogLevel.Trace => ANSI_GRAY,