Skip to content

Commit 565c284

Browse files
authored
Merge pull request #132 from serilog/dev
4.1.0 Release
2 parents 37f02f5 + df9f28a commit 565c284

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ The following built-in themes are available:
4343
* `ConsoleTheme.None` - no styling
4444
* `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**
4545
* `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
46+
* `AnsiConsoleTheme.Literate` - an ANSI 256-color version of the "literate" theme
4747
* `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme
4848
* `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme
49+
* `AnsiConsoleTheme.Sixteen` - an ANSI 16-color theme that works well with both light and dark backgrounds
4950

5051
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.
5152

@@ -156,6 +157,18 @@ To configure the console sink with a different theme and include the `SourceCont
156157
}
157158
```
158159

160+
### Performance
161+
162+
Console logging is synchronous and this can cause bottlenecks in some deployment scenarios. For high-volume console logging, consider using [_Serilog.Sinks.Async_](https://github.com/serilog/serilog-sinks-async) to move console writes to a background thread:
163+
164+
```csharp
165+
// dotnet add package serilog.sinks.async
166+
167+
Log.Logger = new LoggerConfiguration()
168+
.WriteTo.Async(wt => wt.Console())
169+
.CreateLogger();
170+
```
171+
159172
### Contributing
160173

161174
Would you like to help make the Serilog console sink even better? We keep a list of issues that are approachable for newcomers under the [up-for-grabs](https://github.com/serilog/serilog-sinks-console/issues?labels=up-for-grabs&state=open) label. Before starting work on a pull request, we suggest commenting on, or raising, an issue on the issue tracker so that we can help and coordinate efforts. For more details check out our [contributing guide](CONTRIBUTING.md).

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2019
3+
image: Visual Studio 2022
44
test: off
55
build_script:
66
- ps: ./Build.ps1
@@ -9,7 +9,7 @@ artifacts:
99
deploy:
1010
- provider: NuGet
1111
api_key:
12-
secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5
12+
secure: oemq1E4zMR+LKQyrR83ZLcugPpZtl5OMKjtpMy/mbPEwuFGS+Oe46427D9KoHYD8
1313
skip_symbols: true
1414
on:
1515
branch: /^(main|dev)$/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
5-
<VersionPrefix>4.0.1</VersionPrefix>
5+
<VersionPrefix>4.1.0</VersionPrefix>
66
<Authors>Serilog Contributors</Authors>
77
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;net5.0</TargetFrameworks>
88
<LangVersion>8.0</LangVersion>

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class AnsiConsoleTheme : ConsoleTheme
4040
/// </summary>
4141
public static AnsiConsoleTheme Literate { get; } = AnsiConsoleThemes.Literate;
4242

43+
/// <summary>
44+
/// A theme in the style of the original <i>Serilog.Sinks.Literate</i> using only standard 16 terminal colors that will work on light backgrounds.
45+
/// </summary>
46+
public static AnsiConsoleTheme Sixteen { get; } = AnsiConsoleThemes.Sixteen;
47+
4348
readonly IReadOnlyDictionary<ConsoleThemeStyle, string> _styles;
4449
const string AnsiStyleReset = "\x1b[0m";
4550

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,26 @@ static class AnsiConsoleThemes
8080
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m",
8181
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m",
8282
});
83+
84+
public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme(
85+
new Dictionary<ConsoleThemeStyle, string>
86+
{
87+
[ConsoleThemeStyle.Text] = AnsiEscapeSequence.Unthemed,
88+
[ConsoleThemeStyle.SecondaryText] = AnsiEscapeSequence.Unthemed,
89+
[ConsoleThemeStyle.TertiaryText] = AnsiEscapeSequence.Unthemed,
90+
[ConsoleThemeStyle.Invalid] = AnsiEscapeSequence.Yellow,
91+
[ConsoleThemeStyle.Null] = AnsiEscapeSequence.Blue,
92+
[ConsoleThemeStyle.Name] = AnsiEscapeSequence.Unthemed,
93+
[ConsoleThemeStyle.String] = AnsiEscapeSequence.Cyan,
94+
[ConsoleThemeStyle.Number] = AnsiEscapeSequence.Magenta,
95+
[ConsoleThemeStyle.Boolean] = AnsiEscapeSequence.Blue,
96+
[ConsoleThemeStyle.Scalar] = AnsiEscapeSequence.Green,
97+
[ConsoleThemeStyle.LevelVerbose] = AnsiEscapeSequence.Unthemed,
98+
[ConsoleThemeStyle.LevelDebug] = AnsiEscapeSequence.Bold,
99+
[ConsoleThemeStyle.LevelInformation] = AnsiEscapeSequence.BrightCyan,
100+
[ConsoleThemeStyle.LevelWarning] = AnsiEscapeSequence.BrightYellow,
101+
[ConsoleThemeStyle.LevelError] = AnsiEscapeSequence.BrightRed,
102+
[ConsoleThemeStyle.LevelFatal] = AnsiEscapeSequence.BrightRed,
103+
});
83104
}
84105
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2017 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace Serilog.Sinks.SystemConsole.Themes
16+
{
17+
static class AnsiEscapeSequence
18+
{
19+
public const string Unthemed = "";
20+
public const string Reset = "\x1b[0m";
21+
public const string Bold = "\x1b[1m";
22+
23+
public const string Black = "\x1b[30m";
24+
public const string Red = "\x1b[31m";
25+
public const string Green = "\x1b[32m";
26+
public const string Yellow = "\x1b[33m";
27+
public const string Blue = "\x1b[34m";
28+
public const string Magenta = "\x1b[35m";
29+
public const string Cyan = "\x1b[36m";
30+
public const string White = "\x1b[37m";
31+
32+
public const string BrightBlack = "\x1b[30;1m";
33+
public const string BrightRed = "\x1b[31;1m";
34+
public const string BrightGreen = "\x1b[32;1m";
35+
public const string BrightYellow = "\x1b[33;1m";
36+
public const string BrightBlue = "\x1b[34;1m";
37+
public const string BrightMagenta = "\x1b[35;1m";
38+
public const string BrightCyan = "\x1b[36;1m";
39+
public const string BrightWhite = "\x1b[37;1m";
40+
}
41+
}

0 commit comments

Comments
 (0)