Part of the Payroll Engine open-source payroll automation framework. Full documentation at payrollengine.org.
Serilog logging extension for the Payroll Engine. This library provides a bridge between the Payroll Engine ILogger interface and Serilog, enabling structured logging through Serilog's rich ecosystem of sinks and enrichers.
- Adapter implementation of
PayrollEngine.ILoggerusing Serilog - Configuration-based setup via
IConfiguration(appsettings.json) - Support for all log levels: Trace, Debug, Information, Warning, Error, Critical
- Structured logging with message templates and property values
Available on NuGet.org:
dotnet add package PayrollEngine.SerilogRegister Serilog in your application startup using the SetupSerilog extension method:
using PayrollEngine.Serilog;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetupSerilog(); // configures Serilog and registers PayrollLog as ILogger
var app = builder.Build();
// ensure logs are flushed on shutdown
app.Lifetime.ApplicationStopped.Register(global::Serilog.Log.CloseAndFlush);
app.Run();SetupSerilog() does two things:
- Initialises
Serilog.Log.Loggerfrom theIConfiguration(reads theSerilogsection ofappsettings.json). - Registers a
PayrollLoginstance as the activePayrollEngine.Loglogger so that all PE log calls are routed through Serilog.
Configure Serilog in your appsettings.json:
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "logs/payroll-.log",
"rollingInterval": "Day",
"retainedFileCountLimit": 7
}
}
]
}
}Use the Payroll Engine Log class anywhere in your application:
using PayrollEngine;
Log.Information("Processing payroll for {TenantId}", tenantId);
Log.Warning("Retro payrun triggered for {EmployeeId}", employeeId);
Log.Error(exception, "Payroll calculation failed for {EmployeeId}", employeeId);To ensure all buffered log events are written to sinks, call CloseAndFlush when the application shuts down:
global::Serilog.Log.CloseAndFlush();PayrollLog maps each PayrollEngine.ILogger method to the corresponding Serilog level:
| PE method / LogLevel | Serilog LogEventLevel |
|---|---|
Trace |
Verbose |
Debug |
Debug |
Information |
Information |
Warning |
Warning |
Error |
Error |
Critical |
Fatal |
The generic Write(LogLevel level, ...) overload casts the PE LogLevel enum value directly to Serilog.Events.LogEventLevel, so numeric values must match when using Write with an explicit level.
The library consists of two components:
PayrollLog— ImplementsPayrollEngine.ILoggerand delegates all logging calls to the staticSerilog.Log.Logger.ConfigurationExtensions— Provides theSetupSerilog()extension method onIConfigurationthat initialises Serilog from configuration and registersPayrollLogas the activePayrollEngine.Loglogger viaLog.SetLogger().
dotnet build -c Release
dotnet pack -c ReleaseEnvironment variable used during build:
| Variable | Description |
|---|---|
PayrollEnginePackageDir |
Output directory for the NuGet package (optional) |
- Logging with Serilog — license
Apache 2.0
- Payroll Engine Backend — uses this library
- Payroll Engine WebApp — uses this library
- Payroll Engine Console — uses this library
- Serilog documentation — sinks, enrichers, configuration