dragon-iso/src/TeamsISO.Engine/Logging/EngineLogging.cs
Zac Gaetano 27dc0f90c7
Some checks failed
CI / build-and-test (push) Has been cancelled
feat(logging): add EngineLogging.CreateConsole helper
2026-05-07 15:16:17 +00:00

34 lines
1.4 KiB
C#

using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Extensions.Logging;
namespace TeamsISO.Engine.Logging;
/// <summary>
/// Convenience factory for an <see cref="ILoggerFactory"/> wired to Serilog's console sink.
/// Phase A wires console-only; Phase C will add the rolling-file sink under %APPDATA%\TeamsISO\logs\.
/// </summary>
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
};
}