Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
ModeLogger.cs
1using Microsoft.Extensions.Logging;
2
3namespace Gondwana.Logging;
4
8public static partial class EngineLogger
9{
21 private sealed class ModeLogger<T> : ILogger<T>
22 {
23 private static readonly string CategoryName =
24 typeof(T).FullName ?? typeof(T).Name;
25
26 private readonly ILogger _logger;
27
37 public ModeLogger()
38 {
39 // Create once per wrapper instance. EngineLogger clears _loggerCache when factory changes.
40 _logger = GetOrCreateLoggerFactory().CreateLogger(CategoryName);
41 }
42
61 public IDisposable BeginScope<TState>(TState state) where TState : notnull
62 {
63 // NOTE: Scopes don't reliably "flow" across async boundary.
64 // They will work normally in sync mode; in async mode, scope context may be lost.
65 return _logger.BeginScope(state);
66 }
67
80 public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
81
105 public void Log<TState>(
106 LogLevel logLevel,
107 EventId eventId,
108 TState state,
109 Exception? exception,
110 Func<TState, Exception?, string> formatter)
111 {
112 if (!_logger.IsEnabled(logLevel))
113 return;
114
115 if (_mode == EngineLoggingMode.Synchronous)
116 {
117 _logger.Log(logLevel, eventId, state, exception, formatter);
118 return;
119 }
120
121 // Async: queue and drop if full. No sync fallback.
122 Func<object?, Exception?, string> boxedFormatter = (s, e) =>
123 formatter((TState)s!, e);
124
125 var ev = new LogEvent(CategoryName, logLevel, eventId, state, exception, boxedFormatter);
126
127 _ = TryEnqueue(ev); // ignore false (drop)
128 }
129 }
130}
EngineLoggingMode
Specifies the logging mode for the engine.