Skip to content

Commit 5c7a6f2

Browse files
authored
Merge pull request #10 from nblumhardt/dev
Updated to Serilog 2.5, README updates
2 parents 71d7cbe + 6248a0e commit 5c7a6f2

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

README.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# Serilog.Sinks.Console
2-
[![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Console.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Console/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/serilog/serilog/wiki) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) [![Help](https://img.shields.io/badge/stackoverflow-serilog-orange.svg)](http://stackoverflow.com/questions/tagged/serilog)
1+
# Serilog.Sinks.Console [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Console.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Console/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/serilog/serilog/wiki) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) [![Help](https://img.shields.io/badge/stackoverflow-serilog-orange.svg)](http://stackoverflow.com/questions/tagged/serilog)
32

4-
A simple Serilog sink that writes log events as text to `STDOUT`. For **colored console** output, check out [Serilog.Sinks.Literate](https://github.com/serilog/serilog-sinks-literate), which is designed for interactive use.
3+
A Serilog sink that writes log events to the Windows Console or an ANSI terminal via standard output. Coloring and custom themes are supported, including ANSI 256-color themes on macOS, Linux and Windows 10. The default output is plain text; JSON formatting can be plugged in using a package such as [_Serilog.Formatting.Compact_](https://github.com/serilog/serilog-formatting-compact).
54

65
### Getting started
76

@@ -24,31 +23,58 @@ Log.Information("Hello, world!");
2423
Log events will be printed to `STDOUT`:
2524

2625
```
27-
2016-07-08 12:50:51 [Information] Hello, world!
26+
[12:50:51 INF] Hello, world!
2827
```
2928

29+
### Themes
30+
31+
The sink will colorize output by default:
32+
33+
![Colorized Console](https://raw.githubusercontent.com/serilog/serilog-sinks-console/dev/assets/Screenshot.png)
34+
35+
Themes can be specified when configuring the sink:
36+
37+
```csharp
38+
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
39+
```
40+
41+
The following built-in themes are available:
42+
43+
* `ConsoleTheme.None` - no styling
44+
* `SystemConsoleTheme.Literate` - styled to replicate _Serilog.Sinks.Literate_, using the `System.Console` coloring modes supported on all Windows/.NET targets; **this is the default when no theme is specified**
45+
* `SystemConsoleTheme.Grayscale` - a theme using only shades of gray, white, and black
46+
* `AnsiConsoleTheme.Literate` - an ANSI 16-color version of the "literate" theme; we expect to update this to use 256-colors for a more refined look in future
47+
* `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme
48+
* `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme
49+
50+
Adding a new theme is straightforward; examples can be found in the [`SystemConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs) and [`AnsiConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs) classes.
51+
3052
### Output templates
3153

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

3456
```csharp
3557
.WriteTo.Console(
36-
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}")
58+
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
3759
```
3860

3961
The default template, shown in the example above, uses built-in properties like `Timestamp` and `Level`. Properties from events, including those attached using [enrichers](https://github.com/serilog/serilog/wiki/Enrichment), can also appear in the output template.
4062

41-
For more compact level names, use a format such as `{Level:u3}` or `{Level:w3}` for three-character upper- or lowercase level names, respectively.
42-
4363
### JSON output
4464

45-
To write JSON instead of plain text, pass an appropriate `ITextFormatter` to the `Console()` configuration method:
65+
The sink can write JSON output instead of plain text. `CompactJsonFormatter` or `RenderedCompactJsonFormatter` from [Serilog.Formatting.Compact](https://github.com/serilog/serilog-formatting-compact) is recommended:
66+
67+
```powershell
68+
Install-Package Serilog.Formatting.Compact
69+
```
70+
71+
Pass a formatter to the `Console()` configuration method:
4672

4773
```csharp
48-
.WriteTo.Console(new JsonFormatter())
74+
.WriteTo.Console(new CompactJsonFormatter())
4975
```
5076

51-
[Serilog.Formatting.Compact](https://github.com/serilog/serilog-formatting-compact) provides alternatives to the default `JsonFormatter`.
77+
Output theming is not available when custom formatters are used.
5278

5379
### XML `<appSettings>` configuration
5480

@@ -105,4 +131,16 @@ In your `appsettings.json` file, under the `Serilog` node, :
105131
}
106132
```
107133

108-
_Copyright &copy; 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._
134+
### Upgrading from _Serilog.Sinks.Console_ 2.x
135+
136+
To achieve output identical to version 2 of this sink, specify a formatter and output template explicitly:
137+
138+
```csharp
139+
.WriteTo.Console(new MessageTemplateTextFormatter(
140+
"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}",
141+
null))
142+
```
143+
144+
This will bypass theming and use Serilog's built-in message template formatting.
145+
146+
_Copyright &copy; 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._

assets/Screenshot.png

26 KB
Loading

src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</PropertyGroup>
3434

3535
<ItemGroup>
36-
<PackageReference Include="Serilog" Version="2.5.0-dev-00855" />
36+
<PackageReference Include="Serilog" Version="2.5.0" />
3737
</ItemGroup>
3838

3939
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">

0 commit comments

Comments
 (0)