using Microsoft.Extensions.Logging; using Serilog; using Serilog.Extensions.Logging; namespace TeamsISO.Engine.Logging; /// /// Convenience factory for an wired to Serilog's console sink. /// Phase A wires console-only; Phase C will add the rolling-file sink under %APPDATA%\TeamsISO\logs\. /// public static class EngineLogging { public static ILoggerFactory CreateConsole(LogLevel minimum = LogLevel.Information) { var serilog = new LoggerConfiguration() .MinimumLevel.Is(MapLevel(minimum)) .Enrich.WithProperty("Component", "TeamsISO.Engine") .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{Component}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); return new SerilogLoggerFactory(serilog, dispose: true); } private static Serilog.Events.LogEventLevel MapLevel(LogLevel level) => level switch { LogLevel.Trace => Serilog.Events.LogEventLevel.Verbose, LogLevel.Debug => Serilog.Events.LogEventLevel.Debug, LogLevel.Information => Serilog.Events.LogEventLevel.Information, LogLevel.Warning => Serilog.Events.LogEventLevel.Warning, LogLevel.Error => Serilog.Events.LogEventLevel.Error, LogLevel.Critical => Serilog.Events.LogEventLevel.Fatal, _ => Serilog.Events.LogEventLevel.Information }; }