Gondwana Game Engine Development (master) - 2.7.0
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(
118 logLevel,
119 eventId,
120 state,
121 exception,
122 formatter);
123
124 return;
125 }
126
127 // Async: queue and drop if full. No sync fallback.
128 Func<object?, Exception?, string> boxedFormatter = (s, e) =>
129 formatter((TState)s!, e);
130
131 var ev = new LogEvent(
132 CategoryName,
133 logLevel,
134 eventId,
135 state,
136 exception,
137 boxedFormatter);
138
139 _ = TryEnqueue(ev); // ignore false (drop)
140 }
141 }
142}
EngineLoggingMode
Specifies the logging mode for the engine.