Skip to content

Commit

Permalink
Merge pull request #132 from serilog/dev
Browse files Browse the repository at this point in the history
4.1.0 Release
  • Loading branch information
nblumhardt authored Sep 6, 2022
2 parents 37f02f5 + df9f28a commit 565c284
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ The following built-in themes are available:
* `ConsoleTheme.None` - no styling
* `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**
* `SystemConsoleTheme.Grayscale` - a theme using only shades of gray, white, and black
* `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
* `AnsiConsoleTheme.Literate` - an ANSI 256-color version of the "literate" theme
* `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme
* `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme
* `AnsiConsoleTheme.Sixteen` - an ANSI 16-color theme that works well with both light and dark backgrounds

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.

Expand Down Expand Up @@ -156,6 +157,18 @@ To configure the console sink with a different theme and include the `SourceCont
}
```

### Performance

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:

```csharp
// dotnet add package serilog.sinks.async
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(wt => wt.Console())
.CreateLogger();
```

### Contributing

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).
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2019
image: Visual Studio 2022
test: off
build_script:
- ps: ./Build.ps1
Expand All @@ -9,7 +9,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5
secure: oemq1E4zMR+LKQyrR83ZLcugPpZtl5OMKjtpMy/mbPEwuFGS+Oe46427D9KoHYD8
skip_symbols: true
on:
branch: /^(main|dev)$/
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
<VersionPrefix>4.0.1</VersionPrefix>
<VersionPrefix>4.1.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;net5.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class AnsiConsoleTheme : ConsoleTheme
/// </summary>
public static AnsiConsoleTheme Literate { get; } = AnsiConsoleThemes.Literate;

/// <summary>
/// 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.
/// </summary>
public static AnsiConsoleTheme Sixteen { get; } = AnsiConsoleThemes.Sixteen;

readonly IReadOnlyDictionary<ConsoleThemeStyle, string> _styles;
const string AnsiStyleReset = "\x1b[0m";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,26 @@ static class AnsiConsoleThemes
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m",
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m",
});

public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme(
new Dictionary<ConsoleThemeStyle, string>
{
[ConsoleThemeStyle.Text] = AnsiEscapeSequence.Unthemed,
[ConsoleThemeStyle.SecondaryText] = AnsiEscapeSequence.Unthemed,
[ConsoleThemeStyle.TertiaryText] = AnsiEscapeSequence.Unthemed,
[ConsoleThemeStyle.Invalid] = AnsiEscapeSequence.Yellow,
[ConsoleThemeStyle.Null] = AnsiEscapeSequence.Blue,
[ConsoleThemeStyle.Name] = AnsiEscapeSequence.Unthemed,
[ConsoleThemeStyle.String] = AnsiEscapeSequence.Cyan,
[ConsoleThemeStyle.Number] = AnsiEscapeSequence.Magenta,
[ConsoleThemeStyle.Boolean] = AnsiEscapeSequence.Blue,
[ConsoleThemeStyle.Scalar] = AnsiEscapeSequence.Green,
[ConsoleThemeStyle.LevelVerbose] = AnsiEscapeSequence.Unthemed,
[ConsoleThemeStyle.LevelDebug] = AnsiEscapeSequence.Bold,
[ConsoleThemeStyle.LevelInformation] = AnsiEscapeSequence.BrightCyan,
[ConsoleThemeStyle.LevelWarning] = AnsiEscapeSequence.BrightYellow,
[ConsoleThemeStyle.LevelError] = AnsiEscapeSequence.BrightRed,
[ConsoleThemeStyle.LevelFatal] = AnsiEscapeSequence.BrightRed,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2017 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Serilog.Sinks.SystemConsole.Themes
{
static class AnsiEscapeSequence
{
public const string Unthemed = "";
public const string Reset = "\x1b[0m";
public const string Bold = "\x1b[1m";

public const string Black = "\x1b[30m";
public const string Red = "\x1b[31m";
public const string Green = "\x1b[32m";
public const string Yellow = "\x1b[33m";
public const string Blue = "\x1b[34m";
public const string Magenta = "\x1b[35m";
public const string Cyan = "\x1b[36m";
public const string White = "\x1b[37m";

public const string BrightBlack = "\x1b[30;1m";
public const string BrightRed = "\x1b[31;1m";
public const string BrightGreen = "\x1b[32;1m";
public const string BrightYellow = "\x1b[33;1m";
public const string BrightBlue = "\x1b[34;1m";
public const string BrightMagenta = "\x1b[35;1m";
public const string BrightCyan = "\x1b[36;1m";
public const string BrightWhite = "\x1b[37;1m";
}
}

0 comments on commit 565c284

Please sign in to comment.