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
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
58 if (string.IsNullOrEmpty(message) && exception is null)
59 return;
60
61 string eventSuffix = eventId.Id != 0 || !string.IsNullOrWhiteSpace(eventId.Name)
62 ? $" [{eventId.Id}:{eventId.Name ?? string.Empty}]"
63 : string.Empty;
64
65 string line = $"[{FormatLevel(logLevel)}] {categoryName}{eventSuffix}: {message}";
66
67 if (exception is not null)
68 line += Environment.NewLine + exception;
69
70 TextWriter writer = logLevel >= LogLevel.Warning
71 ? Console.Error
72 : Console.Out;
73
74 writer.WriteLine(line);
75 }
76
77 private static string FormatLevel(LogLevel level) => level switch
78 {
79 LogLevel.Trace => "trace",
80 LogLevel.Debug => "debug",
81 LogLevel.Information => "info",
82 LogLevel.Warning => "warn",
83 LogLevel.Error => "error",
84 LogLevel.Critical => "critical",
85 _ => level.ToString().ToLowerInvariant()
86 };
87 }
88}
89
93public static class BrowserConsoleLogging
94{
95 private const string ProviderKey = "Gondwana.Blazor.BrowserConsole";
96
101 public static void AttachToEngineLogger()
102 {
103 EngineLogger.RegisterPersistentProvider(
104 ProviderKey,
105 static () => new BrowserConsoleLoggerProvider());
106 }
107}
Writes Microsoft.Extensions.Logging records to the browser developer console without using the deskto...