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
BrowserConsoleLoggerProvider.cs
2using Microsoft.Extensions.Logging;
3
5
21public sealed class BrowserConsoleLoggerProvider : ILoggerProvider
22{
24 public ILogger CreateLogger(string categoryName)
25 {
26 ArgumentException.ThrowIfNullOrWhiteSpace(categoryName);
27 return new BrowserConsoleLogger(categoryName);
28 }
29
31 public void Dispose()
32 {
33 }
34
35 private sealed class BrowserConsoleLogger(string categoryName) : ILogger
36 {
38 public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
39
41 public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None;
42
44 public void Log<TState>(
45 LogLevel logLevel,
46 EventId eventId,
47 TState state,
48 Exception? exception,
49 Func<TState, Exception?, string> formatter)
50 {
51 ArgumentNullException.ThrowIfNull(formatter);
52
53 if (!IsEnabled(logLevel))
54 return;
55
56 string message = formatter(state, exception);
57 if (string.IsNullOrEmpty(message) && exception is null)
58 return;
59
60 string eventSuffix = eventId.Id != 0 || !string.IsNullOrWhiteSpace(eventId.Name)
61 ? $" [{eventId.Id}:{eventId.Name ?? string.Empty}]"
62 : string.Empty;
63
64 string line = $"[{FormatLevel(logLevel)}] {categoryName}{eventSuffix}: {message}";
65 if (exception is not null)
66 line += Environment.NewLine + exception;
67
68 TextWriter writer = logLevel >= LogLevel.Warning
69 ? Console.Error
70 : Console.Out;
71 writer.WriteLine(line);
72 }
73
74 private static string FormatLevel(LogLevel level) => level switch
75 {
76 LogLevel.Trace => "trace",
77 LogLevel.Debug => "debug",
78 LogLevel.Information => "info",
79 LogLevel.Warning => "warn",
80 LogLevel.Error => "error",
81 LogLevel.Critical => "critical",
82 _ => level.ToString().ToLowerInvariant()
83 };
84 }
85}
86
90public static class BrowserConsoleLogging
91{
92 private const string ProviderKey = "Gondwana.Blazor.BrowserConsole";
93
98 public static void AttachToEngineLogger()
99 {
100 EngineLogger.RegisterPersistentProvider(
101 ProviderKey,
102 static () => new BrowserConsoleLoggerProvider());
103 }
104}
Writes Microsoft.Extensions.Logging records to the browser developer console without using the deskto...