You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-11Lines changed: 49 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
-
# Serilog.Sinks.Console
2
-
[](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master)[](https://www.nuget.org/packages/Serilog.Sinks.Console/)[](https://github.com/serilog/serilog/wiki)[](https://gitter.im/serilog/serilog)[](http://stackoverflow.com/questions/tagged/serilog)
1
+
# Serilog.Sinks.Console [](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master)[](https://www.nuget.org/packages/Serilog.Sinks.Console/)[](https://github.com/serilog/serilog/wiki)[](https://gitter.im/serilog/serilog)[](http://stackoverflow.com/questions/tagged/serilog)
3
2
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).
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
+
30
52
### Output templates
31
53
32
54
The format of events to the console can be modified using the `outputTemplate` configuration parameter:
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.
40
62
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
-
43
63
### JSON output
44
64
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:
46
72
47
73
```csharp
48
-
.WriteTo.Console(newJsonFormatter())
74
+
.WriteTo.Console(newCompactJsonFormatter())
49
75
```
50
76
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.
52
78
53
79
### XML `<appSettings>` configuration
54
80
@@ -105,4 +131,16 @@ In your `appsettings.json` file, under the `Serilog` node, :
0 commit comments