Skip to content

lucadecamillis/serilog-sinks-spectre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Spectre Build status NuGet

C# Serilog sink for Spectre.Console. Started as C# port of the F# package Serilog.Sinks.SpectreConsole, later the code has been refactored to be more in line with the internal design of Spectre.Console.

Usage

Install the package via nuget:

dotnet add package Serilog.Sinks.Spectre

The sink can be enabled using WriteTo.Spectre():

Log.Logger = new LoggerConfiguration()
    .WriteTo.Spectre()
    .CreateLogger();

The format of events to the console can be modified using the outputTemplate configuration parameter:

    .WriteTo.Spectre(outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}")

The sink configuration also supports the restrictedToMinimumLevel and levelSwitch parameters:

    .WriteTo.Spectre(restrictedToMinimumLevel: LogEventLevel.Warning)
    .WriteTo.Spectre(levelSwitch: new LoggingLevelSwitch(LogEventLevel.Warning))

The sink can also be configured via appsettings.json using the Microsoft.Extensions.Configuration package:

{
    "Serilog": {
        "MinimumLevel": "Debug",
        "WriteTo": [
            {
                "Name": "Spectre",
                "Args": {
                    "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}"
                }
            }
        ]
    }
}

Special attention has been paid to the integration of Serilog with Microsoft.Extensions.Logging. Check out the Space Library example demo. (taken from spectre.console samples).