using System; using Microsoft.Extensions.Logging; namespace AcDream.Bake; /// /// Minimal writing to stderr with a level prefix. /// MeshExtractor logs failures via ILogger.LogError/LogWarning (dat-read /// anomalies, malformed entries) — per the project's "logger injection for /// silent catches" lesson, the bake tool must NOT wire a NullLogger here or /// every per-id extraction failure goes silent. A tiny hand-rolled logger /// avoids pulling in the Microsoft.Extensions.Logging.Console package /// (not already a transitive dependency) for what is a one-line need. /// public sealed class ConsoleErrorLogger : ILogger { private readonly string _categoryName; public ConsoleErrorLogger(string categoryName) { _categoryName = categoryName; } public IDisposable? BeginScope(TState state) where TState : notnull => null; public bool IsEnabled(LogLevel logLevel) => logLevel >= LogLevel.Warning; public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { if (!IsEnabled(logLevel)) return; var message = formatter(state, exception); Console.Error.WriteLine($"[{logLevel}] {_categoryName}: {message}"); if (exception is not null) Console.Error.WriteLine(exception); } } /// Factory producing instances for any category/type. public sealed class ConsoleErrorLoggerProvider : ILoggerProvider { public ILogger CreateLogger(string categoryName) => new ConsoleErrorLogger(categoryName); public void Dispose() { } }