diff --git a/src/TeamsISO.Engine/Logging/EngineLogging.cs b/src/TeamsISO.Engine/Logging/EngineLogging.cs new file mode 100644 index 0000000..accf2ff --- /dev/null +++ b/src/TeamsISO.Engine/Logging/EngineLogging.cs @@ -0,0 +1,34 @@ +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 + }; +} diff --git a/src/TeamsISO.Engine/TeamsISO.Engine.csproj b/src/TeamsISO.Engine/TeamsISO.Engine.csproj index b6200c8..d6fa014 100644 --- a/src/TeamsISO.Engine/TeamsISO.Engine.csproj +++ b/src/TeamsISO.Engine/TeamsISO.Engine.csproj @@ -8,6 +8,9 @@ + + +