A Serilog sink that writes log events to console using Spectre.Console.
Output is plain text.
The sink is written in F#.
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.
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"
}
}
]
}