feat(logging): add EngineLogging.CreateConsole helper
Some checks failed
CI / build-and-test (push) Has been cancelled
Some checks failed
CI / build-and-test (push) Has been cancelled
This commit is contained in:
parent
f2b4e881e4
commit
27dc0f90c7
2 changed files with 37 additions and 0 deletions
34
src/TeamsISO.Engine/Logging/EngineLogging.cs
Normal file
34
src/TeamsISO.Engine/Logging/EngineLogging.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
<PackageReference Include="System.Reactive" Version="6.0.0" />
|
<PackageReference Include="System.Reactive" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue