PragmaticFlow / Serilog.Sinks.SpectreConsole

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serilog.Sinks.SpectreConsole

build NuGet Gitter

A Serilog sink that writes log events to console using Spectre.Console.
Output is plain text.
The sink is written in F#.

Getting started

The sink is available as a NuGet package.
You can install it using the following command:

Install-Package Serilog.Sinks.SpectreConsole

To enable the sink, use .SpectreConsole() extension method.

Log.Logger = new LoggerConfiguration()
    .WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", minLevel: LogEventLevel.Information)
    .MinimumLevel.Verbose()
    .CreateLogger();

Log.Information("Information level example with {0}", "parameter");

For more information, take a look at examples.

Configuration via appsettings.json

To configure the sink via 'appsettings.json' configuration, you have to install NuGet packages:

Install-Package Microsoft.Extensions.Configuration.Json Install-Package Serilog.Settings.Configuration

Then use ReadFrom.Configuration() method.

var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .Build();

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration()
    .CreateLogger();

In appsettings.json configuration file, write the following section:

"Serilog": {
    "WriteTo": [
      {
        "Name": "SpectreConsole",
        "Args": {
          "outputTemplate": "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
          "minLevel": "Verbose"
        }
      }
    ]
}

About

License:Apache License 2.0


Languages

Language:F# 45.4%Language:PowerShell 31.9%Language:Shell 12.6%Language:C# 10.0%