Skip to content

dahlbyk/serilog-sinks-literate

 
 

Repository files navigation

Serilog.Sinks.Literate Build status NuGet Version Documentation Join the chat at https://gitter.im/serilog/serilog

An alternative colored console sink for Serilog that uses a literate programming-inspired presentation to showcase the structure/type of event data. This is in contrast with the ColoredConsole sink that uses color predominantly to emphasise an event's level.

Screenshot

Getting started

Install the Serilog.Sinks.Literate package from NuGet:

Install-Package Serilog.Sinks.Literate

To configure the sink in C# code, call WriteTo.LiterateConsole() during logger configuration:

var log = new LoggerConfiguration()
    .WriteTo.LiterateConsole()
    .CreateLogger();
    
Log.Information("This will be written to the literate console");

XML <appSettings> configuration

To use the rolling file sink with the Serilog.Settings.AppSettings package, first install that package if you haven't already done so:

Install-Package Serilog.Settings.AppSettings

Instead of configuring the logger in code, call ReadFrom.AppSettings():

var log = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    .CreateLogger();

In your application's App.config or Web.config file, specify the literate sink assembly and required path format under the <appSettings> node:

<configuration>
  <appSettings>
    <add key="serilog:using" value="Serilog.Sinks.Literate" />
    <add key="serilog:write-to:LiterateConsole" />
  <appSettings>
<configuration>

JSON appsettings.json configuration

To use the rolling file sink with Microsoft.Extensions.Configuration, for example with ASP.NET Core or .NET Core, use the Serilog.Settings.Configuration package. First install that package if you have not already done so:

Install-Package Serilog.Settings.Configuration

Instead of configuring the literate console directly in code, call ReadFrom.Configuration():

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

var logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

In your appsettings.json file, under the Serilog node, :

{
  "Serilog": {
    "WriteTo": [
      { "Name": "LiterateConsole" }
    ]
  }
}

Copyright © 2016 Serilog Contributors - Provided under the Apache License, Version 2.0.

About

A console sink for Serilog that pretty-prints embedded properties

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 93.6%
  • PowerShell 6.4%