From 7d5689eec11813560731970cd3a31da7ec1bac5d Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 23 Oct 2017 09:48:54 +1000 Subject: [PATCH 01/85] Dev version bump [Skip CI] --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 693b36a..8155c8c 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -2,7 +2,7 @@ A Serilog sink that writes log events to the console/terminal. - 3.1.1 + 3.1.2 Serilog Contributors net45;netstandard1.3;netcoreapp1.1 Serilog.Sinks.Console From 6d3f7ae1c1ac0337995d1ebbcc4123c92b6a0d9a Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 24 Oct 2017 15:04:41 +1000 Subject: [PATCH 02/85] Minor documentation fix [Skip CI] --- .../ConsoleLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 8c6fce8..78f19b1 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -39,7 +39,7 @@ public static class ConsoleLoggerConfigurationExtensions /// A switch allowing the pass-through minimum level /// to be changed at runtime. /// A message template describing the format used to write to the sink. - /// the default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message}{NewLine}{Exception}". + /// the default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}". /// Supplies culture-specific formatting information, or null. /// Specifies the level at which events will be written to standard error. /// The theme to apply to the styled output. If not specified, From ae6c75b23d9e030818952ffc9169b6673ec2e879 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Sun, 29 Apr 2018 11:15:12 +1000 Subject: [PATCH 03/85] Add additional JSON config sample #30 --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ba2bc0..c07cc78 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,6 @@ var logger = new LoggerConfiguration() ``` In your `appsettings.json` file, under the `Serilog` node, : - ```json { "Serilog": { @@ -131,6 +130,23 @@ In your `appsettings.json` file, under the `Serilog` node, : } ``` +To configure the console sink with a different theme and include the `SourceContext` in the output, change your `appsettings.json` to: +```json +{ + "Serilog": { + "WriteTo": [ + { + "Name": "Console", + "Args": { + "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", + "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {NewLine}{Exception}" + } + } + ] + } +} +``` + ### Upgrading from _Serilog.Sinks.Console_ 2.x To achieve output identical to version 2 of this sink, specify a formatter and output template explicitly: From 150de6639bb1e80c505a4baae3ddb359342ddb68 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Tue, 8 May 2018 22:17:56 +0200 Subject: [PATCH 04/85] README : add example to specify theme in xml config in order to complete serilog/serilog-sinks-console#30 --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c07cc78..7af50dd 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,15 @@ In your application's `App.config` or `Web.config` file, specify the console sin ``` +To configure the console sink with a different theme and include the `SourceContext` in the output, change your `App.config`/`Web.config` to: +```xml + + + + + +``` + ### JSON `appsettings.json` configuration To use the console sink with _Microsoft.Extensions.Configuration_, for example with ASP.NET Core or .NET Core, use the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) package. First install that package if you have not already done so: From c03f763a2a2f882a1b2207c56c82a796eabf3f39 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 9 May 2018 11:32:52 +1000 Subject: [PATCH 05/85] New NuGet key --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 7df8c2f..02761fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x + secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8 skip_symbols: true on: branch: /^(master|dev)$/ From 0c769a83bfe7e231bebf5bb4982395824cce90a2 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Mon, 21 May 2018 08:14:13 +1000 Subject: [PATCH 06/85] Make Theme:Code[TertiaryText] different to [Text] --- .../Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index 997143f..bbed311 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -65,7 +65,7 @@ static class AnsiConsoleThemes { [ConsoleThemeStyle.Text] = "\x1b[38;5;0253m", [ConsoleThemeStyle.SecondaryText] = "\x1b[38;5;0246m", - [ConsoleThemeStyle.TertiaryText] = "\x1b[38;5;0253m", + [ConsoleThemeStyle.TertiaryText] = "\x1b[38;5;0242m", [ConsoleThemeStyle.Invalid] = "\x1b[33;1m", [ConsoleThemeStyle.Null] = "\x1b[38;5;0038m", [ConsoleThemeStyle.Name] = "\x1b[38;5;0081m", From 911a47c3595f89f0b303e7249c8510f094d447a0 Mon Sep 17 00:00:00 2001 From: Maxime Rouiller Date: Fri, 21 Sep 2018 11:31:29 -0400 Subject: [PATCH 07/85] fixing repository url --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 8155c8c..14dbe0b 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -14,6 +14,8 @@ http://serilog.net/images/serilog-sink-nuget.png https://github.com/serilog/serilog-sinks-console https://www.apache.org/licenses/LICENSE-2.0 + https://github.com/serilog/serilog-sinks-console + git true true true From be343cd11809bf7ce5a42b9721e193cee2bb4807 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Fri, 4 Jan 2019 19:07:51 +0100 Subject: [PATCH 08/85] Update Nuget package license specification `licenseUrl` is now deprecated in favor of `license expression` --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 14dbe0b..8053766 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -13,7 +13,7 @@ serilog;console;terminal http://serilog.net/images/serilog-sink-nuget.png https://github.com/serilog/serilog-sinks-console - https://www.apache.org/licenses/LICENSE-2.0 + Apache-2.0 https://github.com/serilog/serilog-sinks-console git true From e6c9b40210c6c08f2f5510046df80a28434fd452 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Tue, 30 Oct 2018 20:59:44 +0100 Subject: [PATCH 09/85] Copy output formatting tests from core serilog repo in order to try to solve #48 --- .../Output/OutputTemplateRendererTests.cs | 351 ++++++++++++++++++ .../Support/DelegatingSink.cs | 34 ++ 2 files changed, 385 insertions(+) create mode 100644 test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs create mode 100644 test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs diff --git a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs new file mode 100644 index 0000000..0a6836b --- /dev/null +++ b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs @@ -0,0 +1,351 @@ +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using Serilog.Events; +using Serilog.Sinks.Console.Tests.Support; +using Serilog.Sinks.SystemConsole.Output; +using Serilog.Sinks.SystemConsole.Themes; +using Xunit; + +namespace Serilog.Sinks.Console.Tests.Output +{ + public class OutputTemplateRendererTests + { + [Fact] + public void UsesFormatProvider() + { + var french = new CultureInfo("fr-FR"); + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message}", french); + var evt = DelegatingSink.GetLogEvent(l => l.Information("{0}", 12.345)); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("12,345", sw.ToString()); + } + + [Fact] + public void MessageTemplatesContainingFormatStringPropertiesRenderCorrectly() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("{Message}", "Hello, world!")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("\"Hello, world!\"", sw.ToString()); + } + + [Fact] + public void UppercaseFormatSpecifierIsSupportedForStrings() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Name:u}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("{Name}", "Nick")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("NICK", sw.ToString()); + } + + [Fact] + public void LowercaseFormatSpecifierIsSupportedForStrings() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Name:w}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("{Name}", "Nick")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("nick", sw.ToString()); + } + + [Theory] + [InlineData(LogEventLevel.Verbose, 1, "V")] + [InlineData(LogEventLevel.Verbose, 2, "Vb")] + [InlineData(LogEventLevel.Verbose, 3, "Vrb")] + [InlineData(LogEventLevel.Verbose, 4, "Verb")] + [InlineData(LogEventLevel.Verbose, 5, "Verbo")] + [InlineData(LogEventLevel.Verbose, 6, "Verbos")] + [InlineData(LogEventLevel.Verbose, 7, "Verbose")] + [InlineData(LogEventLevel.Verbose, 8, "Verbose")] + [InlineData(LogEventLevel.Debug, 1, "D")] + [InlineData(LogEventLevel.Debug, 2, "De")] + [InlineData(LogEventLevel.Debug, 3, "Dbg")] + [InlineData(LogEventLevel.Debug, 4, "Dbug")] + [InlineData(LogEventLevel.Debug, 5, "Debug")] + [InlineData(LogEventLevel.Debug, 6, "Debug")] + [InlineData(LogEventLevel.Information, 1, "I")] + [InlineData(LogEventLevel.Information, 2, "In")] + [InlineData(LogEventLevel.Information, 3, "Inf")] + [InlineData(LogEventLevel.Information, 4, "Info")] + [InlineData(LogEventLevel.Information, 5, "Infor")] + [InlineData(LogEventLevel.Information, 6, "Inform")] + [InlineData(LogEventLevel.Information, 7, "Informa")] + [InlineData(LogEventLevel.Information, 8, "Informat")] + [InlineData(LogEventLevel.Information, 9, "Informati")] + [InlineData(LogEventLevel.Information, 10, "Informatio")] + [InlineData(LogEventLevel.Information, 11, "Information")] + [InlineData(LogEventLevel.Information, 12, "Information")] + [InlineData(LogEventLevel.Error, 1, "E")] + [InlineData(LogEventLevel.Error, 2, "Er")] + [InlineData(LogEventLevel.Error, 3, "Err")] + [InlineData(LogEventLevel.Error, 4, "Eror")] + [InlineData(LogEventLevel.Error, 5, "Error")] + [InlineData(LogEventLevel.Error, 6, "Error")] + [InlineData(LogEventLevel.Fatal, 1, "F")] + [InlineData(LogEventLevel.Fatal, 2, "Fa")] + [InlineData(LogEventLevel.Fatal, 3, "Ftl")] + [InlineData(LogEventLevel.Fatal, 4, "Fatl")] + [InlineData(LogEventLevel.Fatal, 5, "Fatal")] + [InlineData(LogEventLevel.Fatal, 6, "Fatal")] + [InlineData(LogEventLevel.Warning, 1, "W")] + [InlineData(LogEventLevel.Warning, 2, "Wn")] + [InlineData(LogEventLevel.Warning, 3, "Wrn")] + [InlineData(LogEventLevel.Warning, 4, "Warn")] + [InlineData(LogEventLevel.Warning, 5, "Warni")] + [InlineData(LogEventLevel.Warning, 6, "Warnin")] + [InlineData(LogEventLevel.Warning, 7, "Warning")] + [InlineData(LogEventLevel.Warning, 8, "Warning")] + public void FixedLengthLevelIsSupported( + LogEventLevel level, + int width, + string expected) + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, $"{{Level:t{width}}}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Write(level, "Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal(expected, sw.ToString()); + } + + [Fact] + public void FixedLengthLevelSupportsUpperCasing() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Level:u3}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("INF", sw.ToString()); + } + + [Fact] + public void FixedLengthLevelSupportsLowerCasing() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Level:w3}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("inf", sw.ToString()); + } + + [Fact] + public void DefaultLevelLengthIsFullText() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Level}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("Information", sw.ToString()); + } + + [Fact] + public void AligmentAndWidthCanBeCombined() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Level,5:w3}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal(" inf", sw.ToString()); + } + + enum Size + { + Large + } + + class SizeFormatter : IFormatProvider, ICustomFormatter + { + readonly IFormatProvider _innerFormatProvider; + + public SizeFormatter(IFormatProvider innerFormatProvider) + { + _innerFormatProvider = innerFormatProvider; + } + + public object GetFormat(Type formatType) + { + return formatType == typeof(ICustomFormatter) ? this : _innerFormatProvider.GetFormat(formatType); + } + + public string Format(string format, object arg, IFormatProvider formatProvider) + { + if (arg is Size size) + return size == Size.Large ? "Huge" : size.ToString(); + + if (arg is IFormattable formattable) + return formattable.ToString(format, _innerFormatProvider); + + return arg.ToString(); + } + } + + [Fact] + public void AppliesCustomFormatterToEnums() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message}", new SizeFormatter(CultureInfo.InvariantCulture)); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Size {Size}", Size.Large)); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("Size Huge", sw.ToString()); + } + + [Fact] + public void NonMessagePropertiesAreRendered() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).Information("Hello from {Bar}!", "bar")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("{ Foo: 42 }", sw.ToString()); + } + + [Fact] + public void NonMessagePositionalPropertiesAreRendered() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).Information("Hello from {0}!", "bar")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("{ Foo: 42 }", sw.ToString()); + } + + [Fact] + public void DoNotDuplicatePropertiesAlreadyRenderedInOutputTemplate() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Foo} {Properties}", CultureInfo.InvariantCulture); + var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).ForContext("Bar", 42).Information("Hello from bar!")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal("42 { Bar: 42 }", sw.ToString()); + } + + [Theory] + [InlineData("", "Hello, \"World\"!")] + [InlineData(":j", "Hello, \"World\"!")] + [InlineData(":l", "Hello, World!")] + [InlineData(":lj", "Hello, World!")] + [InlineData(":jl", "Hello, World!")] + public void AppliesLiteralFormattingToMessageStringsWhenSpecified(string format, string expected) + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message" + format + "}", null); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello, {Name}!", "World")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal(expected, sw.ToString()); + } + + [Theory] + [InlineData("", "{ Name: \"World\" }")] + [InlineData(":j", "{\"Name\":\"World\"}")] + [InlineData(":lj", "{\"Name\":\"World\"}")] + [InlineData(":jl", "{\"Name\":\"World\"}")] + public void AppliesJsonFormattingToMessageStructuresWhenSpecified(string format, string expected) + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message" + format + "}", null); + var evt = DelegatingSink.GetLogEvent(l => l.Information("{@Obj}", new { Name = "World" })); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal(expected, sw.ToString()); + } + + [Theory] + [InlineData("", "{ Name: \"World\" }")] + [InlineData(":j", "{\"Name\":\"World\"}")] + [InlineData(":lj", "{\"Name\":\"World\"}")] + [InlineData(":jl", "{\"Name\":\"World\"}")] + public void AppliesJsonFormattingToPropertiesTokenWhenSpecified(string format, string expected) + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties" + format + "}", null); + var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Name", "World").Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + Assert.Equal(expected, sw.ToString()); + } + + [Fact] + public void AnEmptyPropertiesTokenIsAnEmptyStructureValueWithDefaultFormatting() + { + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties}", null); + var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); + var sw = new StringWriter(); + formatter.Format(evt, sw); + + var expected = new StructureValue(Enumerable.Empty()).ToString(); + Assert.Equal(expected, sw.ToString()); + } + + [Theory] + [InlineData("", true)] + [InlineData(":lj", false)] + [InlineData(":jl", false)] + [InlineData(":j", false)] + [InlineData(":l", true)] + public void FormatProviderWithScalarProperties(string format, bool shouldUseCustomFormatter) + { + var frenchFormatProvider = new CultureInfo("fr-FR"); + var defaultFormatProvider = CultureInfo.InvariantCulture; + + var date = new DateTime(2018, 01, 01); + var number = 12.345; + + var expectedFormattedDate = shouldUseCustomFormatter + ? date.ToString(frenchFormatProvider) + : date.ToString("O", defaultFormatProvider); + var expectedFormattedNumber = shouldUseCustomFormatter + ? number.ToString(frenchFormatProvider) + : number.ToString(defaultFormatProvider); + + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message" + format + "}", frenchFormatProvider); + var evt = DelegatingSink.GetLogEvent(l => + { + l.Information("{MyDate}{MyNumber}", date, number); + }); + var sw = new StringWriter(); + formatter.Format(evt, sw); + + Assert.Contains(expectedFormattedDate, sw.ToString()); + Assert.Contains(expectedFormattedNumber, sw.ToString()); + } + + [Theory] + [InlineData("", true)] + [InlineData(":lj", false)] + [InlineData(":jl", false)] + [InlineData(":j", false)] + [InlineData(":l", true)] + public void FormatProviderWithDestructuredProperties(string format, bool shouldUseCustomFormatter) + { + var frenchFormatProvider = new CultureInfo("fr-FR"); + var defaultFormatProvider = CultureInfo.InvariantCulture; + + var date = new DateTime(2018, 01, 01); + var number = 12.345; + + var expectedFormattedDate = shouldUseCustomFormatter + ? date.ToString(frenchFormatProvider) + : date.ToString("O", defaultFormatProvider); + var expectedFormattedNumber = shouldUseCustomFormatter + ? number.ToString(frenchFormatProvider) + : number.ToString(defaultFormatProvider); + + var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message" + format + "}", frenchFormatProvider); + var evt = DelegatingSink.GetLogEvent(l => + { + l.Information("{@Item}", new + { + MyDate = date, + MyNumber = number + }); + }); + var sw = new StringWriter(); + formatter.Format(evt, sw); + + Assert.Contains(expectedFormattedDate, sw.ToString()); + Assert.Contains(expectedFormattedNumber, sw.ToString()); + } + } +} diff --git a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs new file mode 100644 index 0000000..99a472b --- /dev/null +++ b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs @@ -0,0 +1,34 @@ +using System; +using Serilog.Core; +using Serilog.Events; + +namespace Serilog.Sinks.Console.Tests.Support +{ + public class DelegatingSink : ILogEventSink + { + readonly Action _write; + + public DelegatingSink(Action write) + { + if (write == null) throw new ArgumentNullException(nameof(write)); + _write = write; + } + + public void Emit(LogEvent logEvent) + { + _write(logEvent); + } + + public static LogEvent GetLogEvent(Action writeAction) + { + LogEvent result = null; + var l = new LoggerConfiguration() + .MinimumLevel.Verbose() + .WriteTo.Sink(new DelegatingSink(le => result = le)) + .CreateLogger(); + + writeAction(l); + return result; + } + } +} From ac0468d5da3e7e275bf934810dd620b3cc3a8ecd Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Sun, 18 Nov 2018 16:08:00 +0100 Subject: [PATCH 10/85] Update the test to make them pass Hence documenting the current formatting behavior in the Console Sink --- .../Output/OutputTemplateRendererTests.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs index 0a6836b..6763792 100644 --- a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs @@ -200,7 +200,7 @@ public void NonMessagePropertiesAreRendered() var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).Information("Hello from {Bar}!", "bar")); var sw = new StringWriter(); formatter.Format(evt, sw); - Assert.Equal("{ Foo: 42 }", sw.ToString()); + Assert.Equal("{Foo=42}", sw.ToString()); } [Fact] @@ -210,7 +210,7 @@ public void NonMessagePositionalPropertiesAreRendered() var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).Information("Hello from {0}!", "bar")); var sw = new StringWriter(); formatter.Format(evt, sw); - Assert.Equal("{ Foo: 42 }", sw.ToString()); + Assert.Equal("{Foo=42}", sw.ToString()); } [Fact] @@ -220,7 +220,7 @@ public void DoNotDuplicatePropertiesAlreadyRenderedInOutputTemplate() var evt = DelegatingSink.GetLogEvent(l => l.ForContext("Foo", 42).ForContext("Bar", 42).Information("Hello from bar!")); var sw = new StringWriter(); formatter.Format(evt, sw); - Assert.Equal("42 { Bar: 42 }", sw.ToString()); + Assert.Equal("42 {Bar=42}", sw.ToString()); } [Theory] @@ -239,10 +239,10 @@ public void AppliesLiteralFormattingToMessageStringsWhenSpecified(string format, } [Theory] - [InlineData("", "{ Name: \"World\" }")] - [InlineData(":j", "{\"Name\":\"World\"}")] - [InlineData(":lj", "{\"Name\":\"World\"}")] - [InlineData(":jl", "{\"Name\":\"World\"}")] + [InlineData("", "{Name=\"World\"}")] + [InlineData(":j", "{\"Name\": \"World\"}")] + [InlineData(":lj", "{\"Name\": \"World\"}")] + [InlineData(":jl", "{\"Name\": \"World\"}")] public void AppliesJsonFormattingToMessageStructuresWhenSpecified(string format, string expected) { var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Message" + format + "}", null); @@ -253,10 +253,10 @@ public void AppliesJsonFormattingToMessageStructuresWhenSpecified(string format, } [Theory] - [InlineData("", "{ Name: \"World\" }")] - [InlineData(":j", "{\"Name\":\"World\"}")] - [InlineData(":lj", "{\"Name\":\"World\"}")] - [InlineData(":jl", "{\"Name\":\"World\"}")] + [InlineData("", "{Name=\"World\"}")] + [InlineData(":j", "{\"Name\": \"World\"}")] + [InlineData(":lj", "{\"Name\": \"World\"}")] + [InlineData(":jl", "{\"Name\": \"World\"}")] public void AppliesJsonFormattingToPropertiesTokenWhenSpecified(string format, string expected) { var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties" + format + "}", null); @@ -267,21 +267,26 @@ public void AppliesJsonFormattingToPropertiesTokenWhenSpecified(string format, s } [Fact] - public void AnEmptyPropertiesTokenIsAnEmptyStructureValueWithDefaultFormatting() + public void AnEmptyPropertiesTokenIsAnEmptyStructureValue() { var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Properties}", null); var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); var sw = new StringWriter(); formatter.Format(evt, sw); - var expected = new StructureValue(Enumerable.Empty()).ToString(); - Assert.Equal(expected, sw.ToString()); + // /!\ different behavior from Serilog Core : https://github.com/serilog/serilog/blob/5c3a7821aa0f654e551dc21e8e19089f6767666b/test/Serilog.Tests/Formatting/Display/MessageTemplateTextFormatterTests.cs#L268-L278 + // + // var expected = new StructureValue(Enumerable.Empty()).ToString(); + // // expected == "{ }" + // Assert.Equal(expected, sw.ToString()); + // + Assert.Equal("{}", sw.ToString()); } [Theory] [InlineData("", true)] - [InlineData(":lj", false)] - [InlineData(":jl", false)] + [InlineData(":lj", true)] + [InlineData(":jl", true)] [InlineData(":j", false)] [InlineData(":l", true)] public void FormatProviderWithScalarProperties(string format, bool shouldUseCustomFormatter) From aba33ef7b3bf8aaa0a573a5bd4d2b89587d4a961 Mon Sep 17 00:00:00 2001 From: Thibaud Desodt Date: Fri, 4 Jan 2019 17:42:06 +0100 Subject: [PATCH 11/85] Fix .sln file to remove reference to inexisting file --- serilog-sinks-console.sln | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/serilog-sinks-console.sln b/serilog-sinks-console.sln index 6a6a8d4..365f9f9 100644 --- a/serilog-sinks-console.sln +++ b/serilog-sinks-console.sln @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5 Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md LICENSE = LICENSE - NuGet.Config = NuGet.Config README.md = README.md assets\Serilog.snk = assets\Serilog.snk EndProjectSection @@ -26,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Console.Tests EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{CF817664-4CEC-4B6A-9C57-A0D687757D82}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "sample\ConsoleDemo\ConsoleDemo.csproj", "{DBF4907A-63A2-4895-8DEF-59F90C20380B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleDemo", "sample\ConsoleDemo\ConsoleDemo.csproj", "{DBF4907A-63A2-4895-8DEF-59F90C20380B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,4 +54,7 @@ Global {1D56534C-4009-42C2-A573-789CAE6B8AA9} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23} {DBF4907A-63A2-4895-8DEF-59F90C20380B} = {CF817664-4CEC-4B6A-9C57-A0D687757D82} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {43C32ED4-D39A-4E27-AE99-7BB8C883833C} + EndGlobalSection EndGlobal From d2d64b57fd1bc9a06801ac1f4e645ded59146ac7 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Tue, 12 Mar 2019 22:58:22 +0300 Subject: [PATCH 12/85] pad check --- .../Sinks/SystemConsole/Rendering/Padding.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs index 4d6451e..0d7f424 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs @@ -32,18 +32,20 @@ public static void Apply(TextWriter output, string value, Alignment? alignment) return; } - var pad = alignment.Value.Width - value.Length; - if (alignment.Value.Direction == AlignmentDirection.Left) output.Write(value); - if (pad <= PaddingChars.Length) - { - output.Write(PaddingChars, 0, pad); - } - else + var pad = alignment.Value.Width - value.Length; + if (pad > 0) { - output.Write(new string(' ', pad)); + if (pad <= PaddingChars.Length) + { + output.Write(PaddingChars, 0, pad); + } + else + { + output.Write(new string(' ', pad)); + } } if (alignment.Value.Direction == AlignmentDirection.Right) From 3a170af68e0619a440aeb9869b0c5be4ce39c350 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Tue, 12 Mar 2019 23:02:12 +0300 Subject: [PATCH 13/85] spell check --- .../Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs | 2 +- .../Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs | 2 +- .../Sinks/SystemConsole/Themes/SystemConsoleTheme.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index 77345da..3ff6ce8 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -36,7 +36,7 @@ public class AnsiConsoleTheme : ConsoleTheme public static AnsiConsoleTheme Grayscale { get; } = AnsiConsoleThemes.Grayscale; /// - /// A theme in the syle of the original Serilog.Sinks.Literate. + /// A theme in the style of the original Serilog.Sinks.Literate. /// public static AnsiConsoleTheme Literate { get; } = AnsiConsoleThemes.Literate; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs index 2106801..fa78675 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs @@ -75,7 +75,7 @@ public enum ConsoleThemeStyle Scalar, /// - /// Unrecogized literal values, e.g. instances. + /// Unrecognized literal values, e.g. instances. /// [Obsolete("Use ConsoleThemeStyle.Scalar instead"), EditorBrowsable(EditorBrowsableState.Never)] Object = Scalar, diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index 828cf07..68b7950 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -31,7 +31,7 @@ public class SystemConsoleTheme : ConsoleTheme public static SystemConsoleTheme Grayscale { get; } = SystemConsoleThemes.Grayscale; /// - /// A theme in the syle of the original Serilog.Sinks.Literate. + /// A theme in the style of the original Serilog.Sinks.Literate. /// public static SystemConsoleTheme Literate { get; } = SystemConsoleThemes.Literate; From bed2f43a39f1d95b242f0c8ef194adbdbf10141d Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Tue, 12 Mar 2019 23:11:04 +0300 Subject: [PATCH 14/85] code cleanup --- .../Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs | 3 +-- .../Sinks/SystemConsole/Output/LevelTokenRenderer.cs | 1 + .../SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs | 3 +-- test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs index e2ea4dc..bfcf80b 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -37,8 +37,7 @@ public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IForm public override void Render(LogEvent logEvent, TextWriter output) { // If a property is missing, don't render anything (message templates render the raw token here). - LogEventPropertyValue propertyValue; - if (!logEvent.Properties.TryGetValue(_token.PropertyName, out propertyValue)) + if (!logEvent.Properties.TryGetValue(_token.PropertyName, out LogEventPropertyValue propertyValue)) { Padding.Apply(output, "", _token.Alignment); return; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs index 466632d..99a5c1a 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs @@ -25,6 +25,7 @@ class LevelTokenRenderer : OutputTemplateTokenRenderer { readonly ConsoleTheme _theme; readonly PropertyToken _levelToken; + static readonly Dictionary Levels = new Dictionary { { LogEventLevel.Verbose, ConsoleThemeStyle.LevelVerbose }, diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs index 9fa9ca4..da65256 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs @@ -66,8 +66,7 @@ int RenderTextToken(TextToken tt, TextWriter output) int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary properties, TextWriter output) { - LogEventPropertyValue propertyValue; - if (!properties.TryGetValue(pt.PropertyName, out propertyValue)) + if (!properties.TryGetValue(pt.PropertyName, out LogEventPropertyValue propertyValue)) { var count = 0; using (_theme.Apply(output, ConsoleThemeStyle.Invalid, ref count)) diff --git a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs index 99a472b..1a0df7b 100644 --- a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs +++ b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs @@ -10,8 +10,7 @@ public class DelegatingSink : ILogEventSink public DelegatingSink(Action write) { - if (write == null) throw new ArgumentNullException(nameof(write)); - _write = write; + _write = write ?? throw new ArgumentNullException(nameof(write)); } public void Emit(LogEvent logEvent) From da93355b2e406fe38cdb3caaa5f4644d60ab8fee Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Wed, 13 Mar 2019 00:43:00 +0300 Subject: [PATCH 15/85] code cleanup --- .../Sinks/SystemConsole/Themes/SystemConsoleTheme.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index 68b7950..d1839f7 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -40,8 +40,6 @@ public class SystemConsoleTheme : ConsoleTheme /// public static SystemConsoleTheme Colored { get; } = SystemConsoleThemes.Colored; - readonly IReadOnlyDictionary _styles; - /// /// Construct a theme given a set of styles. /// @@ -49,11 +47,11 @@ public class SystemConsoleTheme : ConsoleTheme public SystemConsoleTheme(IReadOnlyDictionary styles) { if (styles == null) throw new ArgumentNullException(nameof(styles)); - _styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); + Styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); } /// - public IReadOnlyDictionary Styles => _styles; + public IReadOnlyDictionary Styles { get; private set; } /// public override bool CanBuffer => false; @@ -64,7 +62,7 @@ public SystemConsoleTheme(IReadOnlyDictionary public override int Set(TextWriter output, ConsoleThemeStyle style) { - if (_styles.TryGetValue(style, out var wcts)) + if (Styles.TryGetValue(style, out var wcts)) { if (wcts.Foreground.HasValue) Console.ForegroundColor = wcts.Foreground.Value; From 53b681aa2b63be4d89c731f6cd7af6f14e47b3ca Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Wed, 13 Mar 2019 01:07:13 +0300 Subject: [PATCH 16/85] Revert "pad check" This reverts commit d2d64b57fd1bc9a06801ac1f4e645ded59146ac7. --- .../Sinks/SystemConsole/Rendering/Padding.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs index 0d7f424..4d6451e 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs @@ -32,20 +32,18 @@ public static void Apply(TextWriter output, string value, Alignment? alignment) return; } + var pad = alignment.Value.Width - value.Length; + if (alignment.Value.Direction == AlignmentDirection.Left) output.Write(value); - var pad = alignment.Value.Width - value.Length; - if (pad > 0) + if (pad <= PaddingChars.Length) + { + output.Write(PaddingChars, 0, pad); + } + else { - if (pad <= PaddingChars.Length) - { - output.Write(PaddingChars, 0, pad); - } - else - { - output.Write(new string(' ', pad)); - } + output.Write(new string(' ', pad)); } if (alignment.Value.Direction == AlignmentDirection.Right) From 597d51fabc13d9bd8f8f789fde93593e3d745e51 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Wed, 13 Mar 2019 11:13:36 +0300 Subject: [PATCH 17/85] more code cleanup --- sample/ConsoleDemo/Program.cs | 2 +- .../ConsoleLoggerConfigurationExtensions.cs | 8 ++-- .../Sinks/SystemConsole/ConsoleSink.cs | 14 +++--- .../Formatting/ThemedDisplayValueFormatter.cs | 12 +++-- .../Formatting/ThemedJsonValueFormatter.cs | 12 +++-- .../Formatting/ThemedValueFormatterState.cs | 5 +- .../Output/EventPropertyTokenRenderer.cs | 4 +- .../SystemConsole/Output/LevelOutputFormat.cs | 46 ++++++++++--------- .../Output/LevelTokenRenderer.cs | 2 +- .../Output/TimestampTokenRenderer.cs | 2 + .../SystemConsole/Platform/WindowsConsole.cs | 6 +-- .../Sinks/SystemConsole/Rendering/Casing.cs | 6 ++- .../Sinks/SystemConsole/Rendering/Padding.cs | 5 +- .../ThemedMessageTemplateRenderer.cs | 6 +-- .../SystemConsole/Themes/AnsiConsoleThemes.cs | 8 ++-- .../SystemConsole/Themes/ConsoleTheme.cs | 4 +- .../SystemConsole/Themes/ConsoleThemeStyle.cs | 11 +++-- .../SystemConsole/Themes/EmptyConsoleTheme.cs | 7 +-- .../Themes/SystemConsoleTheme.cs | 4 +- .../Themes/SystemConsoleThemes.cs | 10 ++-- .../ThemedDisplayValueFormatterTests.cs | 6 +-- .../ThemedJsonValueFormatterTests.cs | 7 +-- .../Output/OutputTemplateRendererTests.cs | 2 +- .../ThemedMessageTemplateRendererTests.cs | 23 ++++------ .../Support/DelegatingSink.cs | 4 +- 25 files changed, 114 insertions(+), 102 deletions(-) diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index dcd9d75..28ce01f 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -1,7 +1,7 @@ using Serilog; +using Serilog.Sinks.SystemConsole.Themes; using System; using System.Threading; -using Serilog.Sinks.SystemConsole.Themes; namespace ConsoleDemo { diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 78f19b1..97c84d1 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; using Serilog.Configuration; using Serilog.Core; using Serilog.Events; using Serilog.Formatting; using Serilog.Sinks.SystemConsole; -using Serilog.Sinks.SystemConsole.Themes; using Serilog.Sinks.SystemConsole.Output; +using Serilog.Sinks.SystemConsole.Themes; +using System; namespace Serilog { @@ -36,11 +36,11 @@ public static class ConsoleLoggerConfigurationExtensions /// Logger sink configuration. /// The minimum level for /// events passed through the sink. Ignored when is specified. + /// A message template describing the format used to write to the sink. + /// Supplies culture-specific formatting information, or null. /// A switch allowing the pass-through minimum level /// to be changed at runtime. - /// A message template describing the format used to write to the sink. /// the default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}". - /// Supplies culture-specific formatting information, or null. /// Specifies the level at which events will be written to standard error. /// The theme to apply to the styled output. If not specified, /// uses . diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index 0aedb49..5592af9 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; -using System.IO; -using System.Text; using Serilog.Core; using Serilog.Events; -using Serilog.Sinks.SystemConsole.Themes; using Serilog.Formatting; using Serilog.Sinks.SystemConsole.Platform; +using Serilog.Sinks.SystemConsole.Themes; +using System; +using System.IO; +using System.Text; namespace Serilog.Sinks.SystemConsole { @@ -30,7 +30,7 @@ class ConsoleSink : ILogEventSink readonly ITextFormatter _formatter; readonly object _syncRoot = new object(); - const int DefaultWriteBuffer = 256; + const int DefaultWriteBufferCapacity = 256; static ConsoleSink() { @@ -56,7 +56,7 @@ public void Emit(LogEvent logEvent) // buffered write here and have no effect when the line is actually written out. if (_theme.CanBuffer) { - var buffer = new StringWriter(new StringBuilder(DefaultWriteBuffer)); + var buffer = new StringWriter(new StringBuilder(DefaultWriteBufferCapacity)); _formatter.Format(logEvent, buffer); lock (_syncRoot) { @@ -76,7 +76,7 @@ public void Emit(LogEvent logEvent) TextWriter SelectOutputStream(LogEventLevel logEventLevel) { - if (!_standardErrorFromLevel.HasValue) + if (_standardErrorFromLevel == null) return Console.Out; return logEventLevel < _standardErrorFromLevel ? Console.Out : Console.Error; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs index e6b3659..38ce0b7 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs @@ -52,12 +52,14 @@ protected override int VisitSequenceValue(ThemedValueFormatterState state, Seque using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('['); - var delim = ""; + var delim = string.Empty; for (var index = 0; index < sequence.Elements.Count; ++index) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; Visit(state, sequence.Elements[index]); @@ -84,12 +86,14 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('{'); - var delim = ""; + var delim = string.Empty; for (var index = 0; index < structure.Properties.Count; ++index) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; @@ -117,12 +121,14 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('{'); - var delim = ""; + var delim = string.Empty; foreach (var element in dictionary.Elements) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs index a8c7ec8..2294ea7 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs @@ -60,12 +60,14 @@ protected override int VisitSequenceValue(ThemedValueFormatterState state, Seque using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('['); - var delim = ""; + var delim = string.Empty; for (var index = 0; index < sequence.Elements.Count; ++index) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; Visit(state.Nest(), sequence.Elements[index]); @@ -84,12 +86,14 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('{'); - var delim = ""; + var delim = string.Empty; for (var index = 0; index < structure.Properties.Count; ++index) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; @@ -132,12 +136,14 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write('{'); - var delim = ""; + var delim = string.Empty; foreach (var element in dictionary.Elements) { if (delim.Length != 0) + { using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(delim); + } delim = ", "; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs index 1c720c0..5fa497e 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs @@ -22,9 +22,6 @@ struct ThemedValueFormatterState public string Format; public bool IsTopLevel; - public ThemedValueFormatterState Nest() - { - return new ThemedValueFormatterState {Output = Output}; - } + public ThemedValueFormatterState Nest() => new ThemedValueFormatterState { Output = Output }; } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs index bfcf80b..19233ea 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -37,9 +37,9 @@ public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IForm public override void Render(LogEvent logEvent, TextWriter output) { // If a property is missing, don't render anything (message templates render the raw token here). - if (!logEvent.Properties.TryGetValue(_token.PropertyName, out LogEventPropertyValue propertyValue)) + if (!logEvent.Properties.TryGetValue(_token.PropertyName, out var propertyValue)) { - Padding.Apply(output, "", _token.Alignment); + Padding.Apply(output, string.Empty, _token.Alignment); return; } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs index 1d4f59f..15d6f40 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs @@ -25,31 +25,33 @@ namespace Serilog.Sinks.SystemConsole.Output /// static class LevelOutputFormat { - static readonly string[][] TitleCaseLevelMap = { - new []{ "V", "Vb", "Vrb", "Verb" }, - new []{ "D", "De", "Dbg", "Dbug" }, - new []{ "I", "In", "Inf", "Info" }, - new []{ "W", "Wn", "Wrn", "Warn" }, - new []{ "E", "Er", "Err", "Eror" }, - new []{ "F", "Fa", "Ftl", "Fatl" } + static readonly string[][] TitleCaseLevelMap = + { + new[] { "V", "Vb", "Vrb", "Verb" }, + new[] { "D", "De", "Dbg", "Dbug" }, + new[] { "I", "In", "Inf", "Info" }, + new[] { "W", "Wn", "Wrn", "Warn" }, + new[] { "E", "Er", "Err", "Eror" }, + new[] { "F", "Fa", "Ftl", "Fatl" }, }; - static readonly string[][] LowercaseLevelMap = { - new []{ "v", "vb", "vrb", "verb" }, - new []{ "d", "de", "dbg", "dbug" }, - new []{ "i", "in", "inf", "info" }, - new []{ "w", "wn", "wrn", "warn" }, - new []{ "e", "er", "err", "eror" }, - new []{ "f", "fa", "ftl", "fatl" } + static readonly string[][] LowercaseLevelMap = + { + new[] { "v", "vb", "vrb", "verb" }, + new[] { "d", "de", "dbg", "dbug" }, + new[] { "i", "in", "inf", "info" }, + new[] { "w", "wn", "wrn", "warn" }, + new[] { "e", "er", "err", "eror" }, + new[] { "f", "fa", "ftl", "fatl" }, }; - static readonly string[][] UppercaseLevelMap = { - new []{ "V", "VB", "VRB", "VERB" }, - new []{ "D", "DE", "DBG", "DBUG" }, - new []{ "I", "IN", "INF", "INFO" }, - new []{ "W", "WN", "WRN", "WARN" }, - new []{ "E", "ER", "ERR", "EROR" }, - new []{ "F", "FA", "FTL", "FATL" } + static readonly string[][] UppercaseLevelMap = + { + new[] { "V", "VB", "VRB", "VERB" }, + new[] { "I", "IN", "INF", "INFO" }, + new[] { "W", "WN", "WRN", "WARN" }, + new[] { "E", "ER", "ERR", "EROR" }, + new[] { "F", "FA", "FTL", "FATL" }, }; public static string GetLevelMoniker(LogEventLevel value, string format = null) @@ -78,7 +80,7 @@ public static string GetLevelMoniker(LogEventLevel value, string format = null) } var index = (int)value; - if (index >= 0 && index <= (int) LogEventLevel.Fatal) + if (index >= 0 && index <= (int)LogEventLevel.Fatal) { switch (format[0]) { diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs index 99a5c1a..54f90a2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs @@ -33,7 +33,7 @@ class LevelTokenRenderer : OutputTemplateTokenRenderer { LogEventLevel.Information, ConsoleThemeStyle.LevelInformation }, { LogEventLevel.Warning, ConsoleThemeStyle.LevelWarning }, { LogEventLevel.Error, ConsoleThemeStyle.LevelError }, - { LogEventLevel.Fatal, ConsoleThemeStyle.LevelFatal } + { LogEventLevel.Fatal, ConsoleThemeStyle.LevelFatal }, }; public LevelTokenRenderer(ConsoleTheme theme, PropertyToken levelToken) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs index 409a230..5eac5e2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs @@ -44,7 +44,9 @@ public override void Render(LogEvent logEvent, TextWriter output) using (_theme.Apply(output, ConsoleThemeStyle.SecondaryText, ref _)) { if (_token.Alignment == null) + { sv.Render(output, _token.Format, _formatProvider); + } else { var buffer = new StringWriter(); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs index f50af78..05c27b2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs @@ -23,7 +23,7 @@ static class WindowsConsole { #if PINVOKE public static void EnableVirtualTerminalProcessing() - { + { #if RUNTIME_INFORMATION if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; @@ -49,10 +49,10 @@ public static void EnableVirtualTerminalProcessing() static extern bool GetConsoleMode(IntPtr handle, out uint mode); [DllImport("kernel32.dll", SetLastError = true)] - static extern bool SetConsoleMode(IntPtr handle, uint mode); + static extern bool SetConsoleMode(IntPtr handle, uint mode); #else public static void EnableVirtualTerminalProcessing() - { + { } #endif } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs index 27e866c..ea9258f 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs @@ -18,9 +18,11 @@ static class Casing { /// /// Apply upper or lower casing to when is provided. - /// Returns when no or invalid format provided + /// Returns when no or invalid format provided. /// - /// The provided with formatting applied + /// Provided string for formatting. + /// Format string. + /// The provided with formatting applied. public static string Format(string value, string format = null) { switch (format) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs index 4d6451e..cd98433 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs @@ -24,9 +24,12 @@ static class Padding /// /// Writes the provided value to the output, applying direction-based padding when is provided. /// + /// Output object to write result. + /// Provided value. + /// The alignment settings to apply when rendering . public static void Apply(TextWriter output, string value, Alignment? alignment) { - if (!alignment.HasValue || value.Length >= alignment.Value.Width) + if (alignment == null || value.Length >= alignment.Value.Width) { output.Write(value); return; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs index da65256..3d16ee0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs @@ -66,7 +66,7 @@ int RenderTextToken(TextToken tt, TextWriter output) int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary properties, TextWriter output) { - if (!properties.TryGetValue(pt.PropertyName, out LogEventPropertyValue propertyValue)) + if (!properties.TryGetValue(pt.PropertyName, out var propertyValue)) { var count = 0; using (_theme.Apply(output, ConsoleThemeStyle.Invalid, ref count)) @@ -115,11 +115,11 @@ int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, Lo if (pt.Alignment.Value.Direction == AlignmentDirection.Left) { var invisible = RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format); - Padding.Apply(output, "", pt.Alignment.Value.Widen(-valueLength)); + Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-valueLength)); return invisible; } - Padding.Apply(output, "", pt.Alignment.Value.Widen(-valueLength)); + Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-valueLength)); return RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format); } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index bbed311..5cbb051 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -36,7 +36,7 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelInformation] = "\x1b[38;5;0015m", [ConsoleThemeStyle.LevelWarning] = "\x1b[38;5;0011m", [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m", - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m" + [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", }); public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme( @@ -54,10 +54,10 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.Scalar] = "\x1b[1m\x1b[37;1m", [ConsoleThemeStyle.LevelVerbose] = "\x1b[30;1m", [ConsoleThemeStyle.LevelDebug] = "\x1b[30;1m", - [ConsoleThemeStyle.LevelInformation] ="\x1b[37;1m", + [ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m", [ConsoleThemeStyle.LevelWarning] = "\x1b[37;1m\x1b[47m", [ConsoleThemeStyle.LevelError] = "\x1b[30m\x1b[47m", - [ConsoleThemeStyle.LevelFatal] = "\x1b[30m\x1b[47m" + [ConsoleThemeStyle.LevelFatal] = "\x1b[30m\x1b[47m", }); public static AnsiConsoleTheme Code { get; } = new AnsiConsoleTheme( @@ -78,7 +78,7 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m", [ConsoleThemeStyle.LevelWarning] = "\x1b[38;5;0229m", [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m", - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m" + [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m", }); } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleTheme.cs index d220cdb..b3921bf 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleTheme.cs @@ -37,13 +37,13 @@ public abstract class ConsoleTheme /// /// Output destination. /// Style to apply. - /// + /// The number of characters written to . public abstract int Set(TextWriter output, ConsoleThemeStyle style); /// /// Reset the output to un-styled colors. /// - /// The output. + /// Output destination. public abstract void Reset(TextWriter output); /// diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs index fa78675..69d231f 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/ConsoleThemeStyle.cs @@ -33,7 +33,7 @@ public enum ConsoleThemeStyle SecondaryText, /// - /// De-emphasized text, for example literal text in output templates and + /// De-emphasized text, for example literal text in output templates and /// punctuation used when writing structured data. /// TertiaryText, @@ -63,9 +63,9 @@ public enum ConsoleThemeStyle /// Numbers. /// Number, - + /// - /// values. + /// values. /// Boolean, @@ -77,7 +77,8 @@ public enum ConsoleThemeStyle /// /// Unrecognized literal values, e.g. instances. /// - [Obsolete("Use ConsoleThemeStyle.Scalar instead"), EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use ConsoleThemeStyle.Scalar instead")] + [EditorBrowsable(EditorBrowsableState.Never)] Object = Scalar, /// @@ -108,6 +109,6 @@ public enum ConsoleThemeStyle /// /// Level indicator. /// - LevelFatal + LevelFatal, } } \ No newline at end of file diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/EmptyConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/EmptyConsoleTheme.cs index 7be5ef4..de74f8c 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/EmptyConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/EmptyConsoleTheme.cs @@ -20,12 +20,9 @@ class EmptyConsoleTheme : ConsoleTheme { public override bool CanBuffer => true; - protected override int ResetCharCount { get; } = 0; + protected override int ResetCharCount { get; } - public override int Set(TextWriter output, ConsoleThemeStyle style) - { - return 0; - } + public override int Set(TextWriter output, ConsoleThemeStyle style) => 0; public override void Reset(TextWriter output) { diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index d1839f7..5eaf7d8 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -51,13 +51,13 @@ public SystemConsoleTheme(IReadOnlyDictionary - public IReadOnlyDictionary Styles { get; private set; } + public IReadOnlyDictionary Styles { get; } /// public override bool CanBuffer => false; /// - protected override int ResetCharCount { get; } = 0; + protected override int ResetCharCount { get; } /// public override int Set(TextWriter output, ConsoleThemeStyle style) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs index 5e77b39..5e202f9 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs @@ -37,7 +37,7 @@ static class SystemConsoleThemes [ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White }, [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow }, [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, - [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red } + [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, }); public static SystemConsoleTheme Grayscale { get; } = new SystemConsoleTheme( @@ -46,7 +46,7 @@ static class SystemConsoleThemes [ConsoleThemeStyle.Text] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White }, [ConsoleThemeStyle.SecondaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Gray }, [ConsoleThemeStyle.TertiaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray }, - [ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.DarkGray}, + [ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.DarkGray }, [ConsoleThemeStyle.Null] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White }, [ConsoleThemeStyle.Name] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Gray }, [ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White }, @@ -56,9 +56,9 @@ static class SystemConsoleThemes [ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray }, [ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray }, [ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White }, - [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.DarkGray}, + [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.DarkGray }, [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black, Background = ConsoleColor.White }, - [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black, Background = ConsoleColor.White } + [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black, Background = ConsoleColor.White }, }); public static SystemConsoleTheme Colored { get; } = new SystemConsoleTheme( @@ -79,7 +79,7 @@ static class SystemConsoleThemes [ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Blue }, [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray, Background = ConsoleColor.Yellow }, [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, - [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red } + [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, }); } } diff --git a/test/Serilog.Sinks.Console.Tests/Formatting/ThemedDisplayValueFormatterTests.cs b/test/Serilog.Sinks.Console.Tests/Formatting/ThemedDisplayValueFormatterTests.cs index c5c9833..2770069 100644 --- a/test/Serilog.Sinks.Console.Tests/Formatting/ThemedDisplayValueFormatterTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Formatting/ThemedDisplayValueFormatterTests.cs @@ -11,11 +11,11 @@ public class ThemedDisplayValueFormatterTests [Theory] [InlineData("Hello", null, "\"Hello\"")] [InlineData("Hello", "l", "Hello")] - public void StringFormattingIsApplied(string s, string format, string expected) + public void StringFormattingIsApplied(string value, string format, string expected) { - var f = new ThemedDisplayValueFormatter(ConsoleTheme.None, null); + var formatter = new ThemedDisplayValueFormatter(ConsoleTheme.None, null); var sw = new StringWriter(); - f.FormatLiteralValue(new ScalarValue(s), sw, format); + formatter.FormatLiteralValue(new ScalarValue(value), sw, format); var actual = sw.ToString(); Assert.Equal(expected, actual); } diff --git a/test/Serilog.Sinks.Console.Tests/Formatting/ThemedJsonValueFormatterTests.cs b/test/Serilog.Sinks.Console.Tests/Formatting/ThemedJsonValueFormatterTests.cs index 3e28425..45a3814 100644 --- a/test/Serilog.Sinks.Console.Tests/Formatting/ThemedJsonValueFormatterTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Formatting/ThemedJsonValueFormatterTests.cs @@ -20,7 +20,7 @@ public TestThemedJsonValueFormatter() public string Format(object literal) { var output = new StringWriter(); - Format(new SequenceValue(new [] {new ScalarValue(literal)}), output, null); + Format(new SequenceValue(new[] { new ScalarValue(literal) }), output, null); var o = output.ToString(); return o.Substring(1, o.Length - 2); } @@ -114,8 +114,9 @@ public void StructuresFormatAsAnObject() [Fact] public void DictionaryWithScalarKeyFormatsAsAnObject() { - var dict = new DictionaryValue(new Dictionary { - { new ScalarValue(12), new ScalarValue(345) } + var dict = new DictionaryValue(new Dictionary + { + { new ScalarValue(12), new ScalarValue(345) }, }); var f = Format(dict); diff --git a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs index 6763792..9454604 100644 --- a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs @@ -343,7 +343,7 @@ public void FormatProviderWithDestructuredProperties(string format, bool shouldU l.Information("{@Item}", new { MyDate = date, - MyNumber = number + MyNumber = number, }); }); var sw = new StringWriter(); diff --git a/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs index 18debf0..2144cea 100644 --- a/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs @@ -1,12 +1,12 @@ -using System; +using Serilog.Sinks.SystemConsole.Formatting; +using Serilog.Sinks.SystemConsole.Rendering; +using Serilog.Sinks.SystemConsole.Themes; +using System; using System.Globalization; using System.IO; using System.Linq; using System.Text; using Xunit; -using Serilog.Sinks.SystemConsole.Themes; -using Serilog.Sinks.SystemConsole.Formatting; -using Serilog.Sinks.SystemConsole.Rendering; namespace Serilog.Sinks.Console.Tests.Rendering { @@ -18,25 +18,20 @@ class Chair public string Back => "straight"; public int[] Legs => new[] { 1, 2, 3, 4 }; + // ReSharper restore UnusedMember.Local - public override string ToString() - { - return "a chair"; - } + public override string ToString() => "a chair"; } class Receipt { // ReSharper disable UnusedMember.Local public decimal Sum => 12.345m; - + public DateTime When => new DateTime(2013, 5, 20, 16, 39, 0); - // ReSharper restore UnusedMember.Local - public override string ToString() - { - return "a receipt"; - } + // ReSharper restore UnusedMember.Local + public override string ToString() => "a receipt"; } [Fact] diff --git a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs index 1a0df7b..35faf1b 100644 --- a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs +++ b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs @@ -21,12 +21,12 @@ public void Emit(LogEvent logEvent) public static LogEvent GetLogEvent(Action writeAction) { LogEvent result = null; - var l = new LoggerConfiguration() + var logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Sink(new DelegatingSink(le => result = le)) .CreateLogger(); - writeAction(l); + writeAction(logger); return result; } } From aff642d5c344508e34a0e7fa57087fdddb56e4f1 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Wed, 13 Mar 2019 11:21:11 +0300 Subject: [PATCH 18/85] oops --- .../Sinks/SystemConsole/Output/LevelOutputFormat.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs index 15d6f40..fdeefe2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs @@ -48,6 +48,7 @@ static class LevelOutputFormat static readonly string[][] UppercaseLevelMap = { new[] { "V", "VB", "VRB", "VERB" }, + new[] { "D", "DE", "DBG", "DBUG" }, new[] { "I", "IN", "INF", "INFO" }, new[] { "W", "WN", "WRN", "WARN" }, new[] { "E", "ER", "ERR", "EROR" }, From 59d2e8fcece167ea777782edf6cbbf118be6c231 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Mon, 6 May 2019 10:54:50 +1000 Subject: [PATCH 19/85] Updated NuGet API Key --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 02761fd..728f79a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,7 +10,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8 + secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/ skip_symbols: true on: branch: /^(master|dev)$/ From b0cecc1acb427363fe1816cd7e4c9a9387b060ac Mon Sep 17 00:00:00 2001 From: Vadim Hatsura Date: Sat, 11 May 2019 13:52:30 +0300 Subject: [PATCH 20/85] #60 add target to netstandard 2.0 --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 6 +++--- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 8053766..6c07dc5 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -4,7 +4,7 @@ A Serilog sink that writes log events to the console/terminal. 3.1.2 Serilog Contributors - net45;netstandard1.3;netcoreapp1.1 + net45;netstandard1.3;netstandard2.0;netcoreapp1.1 Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -20,7 +20,7 @@ true true - true + true True Serilog @@ -35,7 +35,7 @@ - + diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index dc49e7f..e77e5ba 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp1.1 + net461;netcoreapp1.1;netcoreapp2.0 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true From 1ab6bb7a3686b78024fddf3f44015c2f69c53136 Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Sun, 23 Jun 2019 06:18:51 -0500 Subject: [PATCH 21/85] moved code out of critical section that isn't critical --- src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index 5592af9..01d7891 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -58,9 +58,10 @@ public void Emit(LogEvent logEvent) { var buffer = new StringWriter(new StringBuilder(DefaultWriteBufferCapacity)); _formatter.Format(logEvent, buffer); + var formattedLogEventText = buffer.ToString(); lock (_syncRoot) { - output.Write(buffer.ToString()); + output.Write(formattedLogEventText); output.Flush(); } } From cf3c3920c40c1823e81cdbe27e092681a338cfb1 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis <12659251+teo-tsirpanis@users.noreply.github.com> Date: Fri, 5 Jul 2019 12:49:16 +0300 Subject: [PATCH 22/85] Fix an out-of-order line in documentation --- .../ConsoleLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 97c84d1..7c0b7f1 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -37,10 +37,10 @@ public static class ConsoleLoggerConfigurationExtensions /// The minimum level for /// events passed through the sink. Ignored when is specified. /// A message template describing the format used to write to the sink. + /// The default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}". /// Supplies culture-specific formatting information, or null. /// A switch allowing the pass-through minimum level /// to be changed at runtime. - /// the default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}". /// Specifies the level at which events will be written to standard error. /// The theme to apply to the styled output. If not specified, /// uses . From be0da3dbd5ed83810947aa668ad9430be21f400b Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 1 Aug 2019 08:41:27 +1000 Subject: [PATCH 23/85] Synchronize writes across all instances of ConsoleSink --- src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index 01d7891..3116448 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -28,7 +28,7 @@ class ConsoleSink : ILogEventSink readonly LogEventLevel? _standardErrorFromLevel; readonly ConsoleTheme _theme; readonly ITextFormatter _formatter; - readonly object _syncRoot = new object(); + static readonly object _syncRoot = new object(); const int DefaultWriteBufferCapacity = 256; From c308d765704778925b825f4459924f7b2d48a113 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Fri, 2 Aug 2019 10:15:51 +1000 Subject: [PATCH 24/85] Configurable sync root for console sink, enabling scenarios where the application needs to sync with the console, or the application wants to keep multiple console sinks which do not need to be sync'd. --- sample/ConsoleDemo/Program.cs | 54 ++++++++++++++++++- .../ConsoleLoggerConfigurationExtensions.cs | 16 ++++-- .../Sinks/SystemConsole/ConsoleSink.cs | 13 ++++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index 28ce01f..18ce5b8 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -1,13 +1,63 @@ using Serilog; using Serilog.Sinks.SystemConsole.Themes; using System; +using System.Linq; using System.Threading; +using System.Threading.Tasks; namespace ConsoleDemo { public class Program { - public static void Main() + public static void Main(string[] args) + { + if (args != null && args.Length == 1) + { + switch (args[0]) + { + case "--sync-root-default": + SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null); + return; + case "--sync-root-separate": + SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object()); + return; + case "--sync-root-same": + { + var sameSyncRoot = new object(); + SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot); + return; + } + } + } + + AnsiConsoleThemeTest(); + } + + static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2) + { + var logger1 = new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("Logger", "logger1") + .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1) + .CreateLogger(); + + var logger2 = new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("Logger", "logger2") + .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2) + .CreateLogger(); + + var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; + System.Threading.Tasks.Parallel.For(0, 1000, options, (i, loopState) => + { + var logger = (i % 2 == 0) ? logger1 : logger2; + logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId); + }); + + Log.CloseAndFlush(); + } + + static void AnsiConsoleThemeTest() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() @@ -29,7 +79,7 @@ public static void Main() Log.Error(e, "Something went wrong"); } - Log.CloseAndFlush(); + Log.CloseAndFlush(); } static void Fail() diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 7c0b7f1..3b83d75 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -38,6 +38,9 @@ public static class ConsoleLoggerConfigurationExtensions /// events passed through the sink. Ignored when is specified. /// A message template describing the format used to write to the sink. /// The default is "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}". + /// An object that will be used to `lock` (sync) access to the console output. If you specify this, you + /// will have the ability to lock on this object, and guarantee that the console sink will not be about to output anything while + /// the lock is held. /// Supplies culture-specific formatting information, or null. /// A switch allowing the pass-through minimum level /// to be changed at runtime. @@ -52,7 +55,8 @@ public static LoggerConfiguration Console( IFormatProvider formatProvider = null, LoggingLevelSwitch levelSwitch = null, LogEventLevel? standardErrorFromLevel = null, - ConsoleTheme theme = null) + ConsoleTheme theme = null, + object syncRoot = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); @@ -62,7 +66,7 @@ public static LoggerConfiguration Console( theme ?? SystemConsoleThemes.Literate; var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider); - return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel), restrictedToMinimumLevel, levelSwitch); + return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); } /// @@ -71,6 +75,9 @@ public static LoggerConfiguration Console( /// Logger sink configuration. /// Controls the rendering of log events into text, for example to log JSON. To /// control plain text formatting, use the overload that accepts an output template. + /// An object that will be used to `lock` (sync) access to the console output. If you specify this, you + /// will have the ability to lock on this object, and guarantee that the console sink will not be about to output anything while + /// the lock is held. /// The minimum level for /// events passed through the sink. Ignored when is specified. /// A switch allowing the pass-through minimum level @@ -82,12 +89,13 @@ public static LoggerConfiguration Console( ITextFormatter formatter, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, LoggingLevelSwitch levelSwitch = null, - LogEventLevel? standardErrorFromLevel = null) + LogEventLevel? standardErrorFromLevel = null, + object syncRoot = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (formatter == null) throw new ArgumentNullException(nameof(formatter)); - return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel), restrictedToMinimumLevel, levelSwitch); + return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); } } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index 3116448..0c899c4 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -28,7 +28,8 @@ class ConsoleSink : ILogEventSink readonly LogEventLevel? _standardErrorFromLevel; readonly ConsoleTheme _theme; readonly ITextFormatter _formatter; - static readonly object _syncRoot = new object(); + readonly object _syncRoot; + static readonly object _defaultSyncRoot = new object(); const int DefaultWriteBufferCapacity = 256; @@ -41,10 +42,20 @@ public ConsoleSink( ConsoleTheme theme, ITextFormatter formatter, LogEventLevel? standardErrorFromLevel) + : this(theme, formatter, standardErrorFromLevel, _defaultSyncRoot) + { + } + + public ConsoleSink( + ConsoleTheme theme, + ITextFormatter formatter, + LogEventLevel? standardErrorFromLevel, + object syncRoot) { _standardErrorFromLevel = standardErrorFromLevel; _theme = theme ?? throw new ArgumentNullException(nameof(theme)); _formatter = formatter; + _syncRoot = syncRoot ?? _defaultSyncRoot; } public void Emit(LogEvent logEvent) From 95bbfb692a4bbdf204f372988a6b63fdc1e69eed Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Fri, 2 Aug 2019 10:27:56 +1000 Subject: [PATCH 25/85] Fix accidental spaces --- sample/ConsoleDemo/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index 18ce5b8..9f2d3c1 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -79,7 +79,7 @@ static void AnsiConsoleThemeTest() Log.Error(e, "Something went wrong"); } - Log.CloseAndFlush(); + Log.CloseAndFlush(); } static void Fail() From d12536dc5b286e7ca131e57cd96a624874f9e234 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Thu, 15 Aug 2019 15:34:04 +1000 Subject: [PATCH 26/85] revert sample changes --- sample/ConsoleDemo/Program.cs | 48 ----------------------------------- 1 file changed, 48 deletions(-) diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index 9f2d3c1..2ea3259 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -10,54 +10,6 @@ namespace ConsoleDemo public class Program { public static void Main(string[] args) - { - if (args != null && args.Length == 1) - { - switch (args[0]) - { - case "--sync-root-default": - SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null); - return; - case "--sync-root-separate": - SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object()); - return; - case "--sync-root-same": - { - var sameSyncRoot = new object(); - SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot); - return; - } - } - } - - AnsiConsoleThemeTest(); - } - - static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2) - { - var logger1 = new LoggerConfiguration() - .MinimumLevel.Verbose() - .Enrich.WithProperty("Logger", "logger1") - .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1) - .CreateLogger(); - - var logger2 = new LoggerConfiguration() - .MinimumLevel.Verbose() - .Enrich.WithProperty("Logger", "logger2") - .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2) - .CreateLogger(); - - var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; - System.Threading.Tasks.Parallel.For(0, 1000, options, (i, loopState) => - { - var logger = (i % 2 == 0) ? logger1 : logger2; - logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId); - }); - - Log.CloseAndFlush(); - } - - static void AnsiConsoleThemeTest() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() From dbd80a725320b70443aa2100462a31d678775bc8 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Thu, 15 Aug 2019 15:35:12 +1000 Subject: [PATCH 27/85] revert sample changes --- sample/ConsoleDemo/Program.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index 2ea3259..28ce01f 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -1,15 +1,13 @@ using Serilog; using Serilog.Sinks.SystemConsole.Themes; using System; -using System.Linq; using System.Threading; -using System.Threading.Tasks; namespace ConsoleDemo { public class Program { - public static void Main(string[] args) + public static void Main() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() From 7813ab9427278a187345f2e352694d91f79cc76e Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Thu, 15 Aug 2019 15:38:56 +1000 Subject: [PATCH 28/85] Move default synroot to config extensions --- .../ConsoleLoggerConfigurationExtensions.cs | 4 ++++ .../Sinks/SystemConsole/ConsoleSink.cs | 11 +---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 3b83d75..01b085b 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -28,6 +28,7 @@ namespace Serilog /// public static class ConsoleLoggerConfigurationExtensions { + private static object DefaultSyncRoot = new object(); const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"; /// @@ -65,6 +66,8 @@ public static LoggerConfiguration Console( ConsoleTheme.None : theme ?? SystemConsoleThemes.Literate; + syncRoot = syncRoot ?? DefaultSyncRoot; + var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider); return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); } @@ -95,6 +98,7 @@ public static LoggerConfiguration Console( if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (formatter == null) throw new ArgumentNullException(nameof(formatter)); + syncRoot = syncRoot ?? DefaultSyncRoot; return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index 0c899c4..bbe09e0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -29,7 +29,6 @@ class ConsoleSink : ILogEventSink readonly ConsoleTheme _theme; readonly ITextFormatter _formatter; readonly object _syncRoot; - static readonly object _defaultSyncRoot = new object(); const int DefaultWriteBufferCapacity = 256; @@ -38,14 +37,6 @@ static ConsoleSink() WindowsConsole.EnableVirtualTerminalProcessing(); } - public ConsoleSink( - ConsoleTheme theme, - ITextFormatter formatter, - LogEventLevel? standardErrorFromLevel) - : this(theme, formatter, standardErrorFromLevel, _defaultSyncRoot) - { - } - public ConsoleSink( ConsoleTheme theme, ITextFormatter formatter, @@ -55,7 +46,7 @@ public ConsoleSink( _standardErrorFromLevel = standardErrorFromLevel; _theme = theme ?? throw new ArgumentNullException(nameof(theme)); _formatter = formatter; - _syncRoot = syncRoot ?? _defaultSyncRoot; + _syncRoot = syncRoot ?? throw new ArgumentNullException(nameof(syncRoot)); } public void Emit(LogEvent logEvent) From 083b6848f0cdb03e93dcb9f9937ce754b77f5a31 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 15 Aug 2019 16:42:07 +1000 Subject: [PATCH 29/85] Principle-of-least-surprise - use RenderedCompactJsonFormatter in the example JSON configuration --- README.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/README.md b/README.md index 7af50dd..b1996b3 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Install-Package Serilog.Formatting.Compact Pass a formatter to the `Console()` configuration method: ```csharp - .WriteTo.Console(new CompactJsonFormatter()) + .WriteTo.Console(new RenderedCompactJsonFormatter()) ``` Output theming is not available when custom formatters are used. @@ -156,18 +156,6 @@ To configure the console sink with a different theme and include the `SourceCont } ``` -### Upgrading from _Serilog.Sinks.Console_ 2.x - -To achieve output identical to version 2 of this sink, specify a formatter and output template explicitly: - -```csharp - .WriteTo.Console(new MessageTemplateTextFormatter( - "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}", - null)) -``` - -This will bypass theming and use Serilog's built-in message template formatting. - ### 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). From ad280ad85b4b2761d9de21808c6f4546298fb942 Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Tue, 20 Aug 2019 14:50:13 +1000 Subject: [PATCH 30/85] Added `SyncWritesDemo` --- Build.ps1 | 25 ++++++--- sample/SyncWritesDemo/Program.cs | 57 +++++++++++++++++++++ sample/SyncWritesDemo/SyncWritesDemo.csproj | 12 +++++ serilog-sinks-console.sln | 7 +++ 4 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 sample/SyncWritesDemo/Program.cs create mode 100644 sample/SyncWritesDemo/SyncWritesDemo.csproj diff --git a/Build.ps1 b/Build.ps1 index ee4117d..7442231 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,9 +1,9 @@ -echo "build: Build started" +Write-Host "build: Build started" Push-Location $PSScriptRoot if(Test-Path .\artifacts) { - echo "build: Cleaning .\artifacts" + Write-Host "build: Cleaning .\artifacts" Remove-Item .\artifacts -Force -Recurse } @@ -15,13 +15,13 @@ $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch $commitHash = $(git rev-parse --short HEAD) $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] -echo "build: Package version suffix is $suffix" -echo "build: Build version suffix is $buildSuffix" +Write-Host "build: Package version suffix is $suffix" +Write-Host "build: Build version suffix is $buildSuffix" -foreach ($src in ls src/*) { +foreach ($src in Get-ChildItem src/*) { Push-Location $src - echo "build: Packaging project in $src" + Write-Host "build: Packaging project in $src" & dotnet build -c Release --version-suffix=$buildSuffix if ($suffix) { @@ -34,10 +34,21 @@ foreach ($src in ls src/*) { Pop-Location } +foreach ($sample in Get-ChildItem sample/*) { + Push-Location $sample + + Write-Host "build: Testing project in $sample" + + & dotnet build -c Release --version-suffix=$buildSuffix + if($LASTEXITCODE -ne 0) { exit 3 } + + Pop-Location +} + foreach ($test in ls test/*.Tests) { Push-Location $test - echo "build: Testing project in $test" + Write-Host "build: Testing project in $test" & dotnet test -c Release if($LASTEXITCODE -ne 0) { exit 3 } diff --git a/sample/SyncWritesDemo/Program.cs b/sample/SyncWritesDemo/Program.cs new file mode 100644 index 0000000..07713b4 --- /dev/null +++ b/sample/SyncWritesDemo/Program.cs @@ -0,0 +1,57 @@ +using Serilog; +using Serilog.Sinks.SystemConsole.Themes; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace SyncWritesDemo +{ + public static class Program + { + public static void Main(string[] args) + { + Console.WriteLine("A sample of how to sync writes to the console sink."); + + if (args != null && args.Length == 1) + { + switch (args[0]) + { + case "--sync-root-default": + SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null); + return; + case "--sync-root-separate": + SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object()); + return; + case "--sync-root-same": + var sameSyncRoot = new object(); + SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot); + return; + } + } + + Console.WriteLine("Expecting one of the following arguments:{0}--sync-root-default{0}--sync-root-separate{0}--sync-root-same", Environment.NewLine); + } + + static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2) + { + var logger1 = new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("Logger", "logger1") + .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1) + .CreateLogger(); + + var logger2 = new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("Logger", "logger2") + .WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2) + .CreateLogger(); + + var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; + System.Threading.Tasks.Parallel.For(0, 1000, options, (i, loopState) => + { + var logger = (i % 2 == 0) ? logger1 : logger2; + logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId); + }); + } + } +} diff --git a/sample/SyncWritesDemo/SyncWritesDemo.csproj b/sample/SyncWritesDemo/SyncWritesDemo.csproj new file mode 100644 index 0000000..169fe56 --- /dev/null +++ b/sample/SyncWritesDemo/SyncWritesDemo.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.0 + + + + + + + \ No newline at end of file diff --git a/serilog-sinks-console.sln b/serilog-sinks-console.sln index 365f9f9..e223156 100644 --- a/serilog-sinks-console.sln +++ b/serilog-sinks-console.sln @@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{CF8176 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleDemo", "sample\ConsoleDemo\ConsoleDemo.csproj", "{DBF4907A-63A2-4895-8DEF-59F90C20380B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyncWritesDemo", "sample\SyncWritesDemo\SyncWritesDemo.csproj", "{633AE0AD-C9D4-440D-874A-C0F4632DB75F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {DBF4907A-63A2-4895-8DEF-59F90C20380B}.Debug|Any CPU.Build.0 = Debug|Any CPU {DBF4907A-63A2-4895-8DEF-59F90C20380B}.Release|Any CPU.ActiveCfg = Release|Any CPU {DBF4907A-63A2-4895-8DEF-59F90C20380B}.Release|Any CPU.Build.0 = Release|Any CPU + {633AE0AD-C9D4-440D-874A-C0F4632DB75F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {633AE0AD-C9D4-440D-874A-C0F4632DB75F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {633AE0AD-C9D4-440D-874A-C0F4632DB75F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {633AE0AD-C9D4-440D-874A-C0F4632DB75F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -53,6 +59,7 @@ Global {866A028E-27DB-49A0-AC78-E5FEF247C099} = {037440DE-440B-4129-9F7A-09B42D00397E} {1D56534C-4009-42C2-A573-789CAE6B8AA9} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23} {DBF4907A-63A2-4895-8DEF-59F90C20380B} = {CF817664-4CEC-4B6A-9C57-A0D687757D82} + {633AE0AD-C9D4-440D-874A-C0F4632DB75F} = {CF817664-4CEC-4B6A-9C57-A0D687757D82} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {43C32ED4-D39A-4E27-AE99-7BB8C883833C} From 181aec0f4c3d15172adef6795fc305cd566be777 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 21 Aug 2019 12:34:29 +1000 Subject: [PATCH 31/85] disable Mono on travis to speed up the build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 10b9e57..d0cc95b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ matrix: dist: trusty sudo: required dotnet: 1.0.4 + mono: none group: edge script: From d5a5128ba8c2116e6d9adfb9df3c36fe9b192f06 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Aug 2019 12:10:25 +1000 Subject: [PATCH 32/85] run against netcore app 2.2 --- .travis.yml | 2 +- build.sh | 6 +++++- sample/ConsoleDemo/ConsoleDemo.csproj | 2 +- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0cc95b..2032259 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ matrix: - os: linux # Ubuntu 14.04 dist: trusty sudo: required - dotnet: 1.0.4 + dotnet: 2.2.401 mono: none group: edge diff --git a/build.sh b/build.sh index b2dc450..1ea814f 100755 --- a/build.sh +++ b/build.sh @@ -6,14 +6,18 @@ dotnet restore for path in src/**/*.csproj; do dotnet build -f netstandard1.3 -c Release ${path} + dotnet build -f netstandard2.0 -c Release ${path} dotnet build -f netcoreapp1.1 -c Release ${path} done for path in test/*.Tests/*.csproj; do - dotnet test -f netcoreapp1.1 -c Release ${path} + dotnet test -f netcoreapp1.1 -c Release ${path} + dotnet test -f netcoreapp2.2 -c Release ${path} done for path in sample/ConsoleDemo/*.csproj; do dotnet build -f netcoreapp1.1 -c Release ${path} dotnet run -f netcoreapp1.1 --project ${path} + dotnet build -f netcoreapp2.2 -c Release ${path} + dotnet run -f netcoreapp2.2 --project ${path} done diff --git a/sample/ConsoleDemo/ConsoleDemo.csproj b/sample/ConsoleDemo/ConsoleDemo.csproj index 3a2245a..b644b9f 100644 --- a/sample/ConsoleDemo/ConsoleDemo.csproj +++ b/sample/ConsoleDemo/ConsoleDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp1.1;net45 + netcoreapp1.1;net45;netcoreapp2.2 diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index e77e5ba..6d74ba9 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp1.1;netcoreapp2.0 + net461;netcoreapp1.1;netcoreapp2.2 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true From c521c7abcafcc7508bb0a37d096f6224a3f18858 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Aug 2019 12:13:51 +1000 Subject: [PATCH 33/85] simplify build --- .travis.yml | 2 +- build.sh | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2032259..2ed804c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: csharp matrix: include: - os: linux # Ubuntu 14.04 - dist: trusty + dist: xenial sudo: required dotnet: 2.2.401 mono: none diff --git a/build.sh b/build.sh index 1ea814f..64d87ea 100755 --- a/build.sh +++ b/build.sh @@ -5,19 +5,14 @@ dotnet --info dotnet restore for path in src/**/*.csproj; do - dotnet build -f netstandard1.3 -c Release ${path} dotnet build -f netstandard2.0 -c Release ${path} - dotnet build -f netcoreapp1.1 -c Release ${path} done for path in test/*.Tests/*.csproj; do - dotnet test -f netcoreapp1.1 -c Release ${path} dotnet test -f netcoreapp2.2 -c Release ${path} done for path in sample/ConsoleDemo/*.csproj; do - dotnet build -f netcoreapp1.1 -c Release ${path} - dotnet run -f netcoreapp1.1 --project ${path} dotnet build -f netcoreapp2.2 -c Release ${path} dotnet run -f netcoreapp2.2 --project ${path} done From 6f01144680c3bf9354f2e8a5f718ef5effd14295 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 22 Aug 2019 12:13:59 +1000 Subject: [PATCH 34/85] simplify build --- sample/ConsoleDemo/ConsoleDemo.csproj | 2 +- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/ConsoleDemo/ConsoleDemo.csproj b/sample/ConsoleDemo/ConsoleDemo.csproj index b644b9f..f755c4b 100644 --- a/sample/ConsoleDemo/ConsoleDemo.csproj +++ b/sample/ConsoleDemo/ConsoleDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp1.1;net45;netcoreapp2.2 + net45;netcoreapp2.2 diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 6d74ba9..77929eb 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp1.1;netcoreapp2.2 + net461;netcoreapp2.2 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true From a464f75d65e561413b682e1bc26db96e3bc57e77 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Fri, 13 Sep 2019 13:52:17 +1000 Subject: [PATCH 35/85] Fixes #73 - CoC link --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index caea530..8fbb2ed 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,3 @@ # Code of Conduct -Please refer to the [Serilog Code of Conduct](https://github.com/serilog/serilog/blob/dev/CONTRIBUTING.md) which covers all repositories within the Serilog Organisation. \ No newline at end of file +Please refer to the [Serilog Code of Conduct](https://github.com/serilog/serilog/blob/dev/CODE_OF_CONDUCT.md) which covers all repositories within the Serilog Organization. From 65fa7d48c4bee45cf02e699997540b4f6a8a3fea Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Thu, 21 Nov 2019 10:18:15 +0200 Subject: [PATCH 36/85] add applyThemeOnOutputRedirection option to console sink. Fix for https://github.com/serilog/serilog-sinks-console/issues/64 --- .../ConsoleLoggerConfigurationExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 7c0b7f1..0480fc7 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -44,6 +44,7 @@ public static class ConsoleLoggerConfigurationExtensions /// Specifies the level at which events will be written to standard error. /// The theme to apply to the styled output. If not specified, /// uses . + /// Applies the selected or default theme even when output redirection is detected. /// Configuration object allowing method chaining. public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, @@ -52,12 +53,13 @@ public static LoggerConfiguration Console( IFormatProvider formatProvider = null, LoggingLevelSwitch levelSwitch = null, LogEventLevel? standardErrorFromLevel = null, - ConsoleTheme theme = null) + ConsoleTheme theme = null, + bool applyThemeOnOutputRedirection = false) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); - var appliedTheme = System.Console.IsOutputRedirected || System.Console.IsErrorRedirected ? + var appliedTheme = !applyThemeOnOutputRedirection && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ? ConsoleTheme.None : theme ?? SystemConsoleThemes.Literate; From b294696cbb7b105aac779d5097e5d67ac8ccb364 Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Thu, 21 Nov 2019 10:18:30 +0200 Subject: [PATCH 37/85] fix typo --- .../Output/OutputTemplateRendererTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs index 9454604..4857999 100644 --- a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs @@ -143,7 +143,7 @@ public void DefaultLevelLengthIsFullText() } [Fact] - public void AligmentAndWidthCanBeCombined() + public void AlignmentAndWidthCanBeCombined() { var formatter = new OutputTemplateRenderer(ConsoleTheme.None, "{Level,5:w3}", CultureInfo.InvariantCulture); var evt = DelegatingSink.GetLogEvent(l => l.Information("Hello")); From f7167b25278582c7f2667f1091713527cd09c988 Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Thu, 21 Nov 2019 13:41:22 +0200 Subject: [PATCH 38/85] add unit tests --- ...nsoleLoggerConfigurationExtensionsTests.cs | 65 +++++++++++++++++++ .../Serilog.Sinks.Console.Tests.csproj | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs diff --git a/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs new file mode 100644 index 0000000..cc7b886 --- /dev/null +++ b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs @@ -0,0 +1,65 @@ +using System; +using System.IO; +using System.Linq; +using System.Text; +using Xunit; +using System.Linq.Expressions; +using Serilog.Sinks.SystemConsole.Themes; + +namespace Serilog.Sinks.Console.Tests.Configuration +{ + public class ConsoleLoggerConfigurationExtensionsTests + { + [Fact] + public void OutputFormattingIsIgnored() + { + using (var stream = new MemoryStream()) + { + var sw = new StreamWriter(stream); + + System.Console.SetOut(sw); + var config = new LoggerConfiguration() + .WriteTo.Console(theme: AnsiConsoleTheme.Literate, + applyThemeOnOutputRedirection: false); + + var logger = config.CreateLogger(); + + logger.Error("test"); + stream.Position = 0; + + using (var streamReader = new StreamReader(stream)) + { + var result = streamReader.ReadToEnd(); + var controlCharacterCount = result.Count(c => Char.IsControl(c) && !Char.IsWhiteSpace(c)); + Assert.Equal(0, controlCharacterCount); + } + } + } + + [Fact] + public void OutputFormattingIsPresent() + { + using (var stream = new MemoryStream()) + { + var sw = new StreamWriter(stream); + + System.Console.SetOut(sw); + var config = new LoggerConfiguration() + .WriteTo.Console(theme: AnsiConsoleTheme.Literate, + applyThemeOnOutputRedirection: true); + + var logger = config.CreateLogger(); + + logger.Error("test"); + stream.Position = 0; + + using (var streamReader = new StreamReader(stream)) + { + var result = streamReader.ReadToEnd(); + var controlCharacterCount = result.Count(c => Char.IsControl(c) && !Char.IsWhiteSpace(c)); + Assert.NotEqual(0, controlCharacterCount); + } + } + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 77929eb..5922a7c 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -6,7 +6,7 @@ Serilog.Sinks.Console.Tests true 1.6.0 - $(PackageTargetFallback);dnxcore50;portable-net45+win8 + 1.0.4 false false From 71eb8e0d12109eefc6a85b48036ec7373aa2fe9f Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Thu, 21 Nov 2019 13:56:39 +0200 Subject: [PATCH 39/85] remove unused imports --- .../Configuration/ConsoleLoggerConfigurationExtensionsTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs index cc7b886..3d9b57c 100644 --- a/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs @@ -1,9 +1,7 @@ using System; using System.IO; using System.Linq; -using System.Text; using Xunit; -using System.Linq.Expressions; using Serilog.Sinks.SystemConsole.Themes; namespace Serilog.Sinks.Console.Tests.Configuration From 44db5e2d47a3306dbb92b327d96f09041d60c40f Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Thu, 21 Nov 2019 13:57:51 +0200 Subject: [PATCH 40/85] undo commented line in test project --- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 5922a7c..77929eb 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -6,7 +6,7 @@ Serilog.Sinks.Console.Tests true 1.6.0 - + $(PackageTargetFallback);dnxcore50;portable-net45+win8 1.0.4 false false From d9d645b72e99e88c34f4d9bacda82b93988b6bab Mon Sep 17 00:00:00 2001 From: Tjaart Blignaut Date: Fri, 22 Nov 2019 11:51:44 +0200 Subject: [PATCH 41/85] Change parameter name from `applyThemeOnOutputRedirection` to `applyThemeToRedirectedOutput` as suggested. --- .../ConsoleLoggerConfigurationExtensions.cs | 6 +++--- .../ConsoleLoggerConfigurationExtensionsTests.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 0480fc7..14efcc7 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -44,7 +44,7 @@ public static class ConsoleLoggerConfigurationExtensions /// Specifies the level at which events will be written to standard error. /// The theme to apply to the styled output. If not specified, /// uses . - /// Applies the selected or default theme even when output redirection is detected. + /// Applies the selected or default theme even when output redirection is detected. /// Configuration object allowing method chaining. public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, @@ -54,12 +54,12 @@ public static LoggerConfiguration Console( LoggingLevelSwitch levelSwitch = null, LogEventLevel? standardErrorFromLevel = null, ConsoleTheme theme = null, - bool applyThemeOnOutputRedirection = false) + bool applyThemeToRedirectedOutput = false) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); - var appliedTheme = !applyThemeOnOutputRedirection && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ? + var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ? ConsoleTheme.None : theme ?? SystemConsoleThemes.Literate; diff --git a/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs index 3d9b57c..74596c5 100644 --- a/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Configuration/ConsoleLoggerConfigurationExtensionsTests.cs @@ -18,7 +18,7 @@ public void OutputFormattingIsIgnored() System.Console.SetOut(sw); var config = new LoggerConfiguration() .WriteTo.Console(theme: AnsiConsoleTheme.Literate, - applyThemeOnOutputRedirection: false); + applyThemeToRedirectedOutput: false); var logger = config.CreateLogger(); @@ -44,7 +44,7 @@ public void OutputFormattingIsPresent() System.Console.SetOut(sw); var config = new LoggerConfiguration() .WriteTo.Console(theme: AnsiConsoleTheme.Literate, - applyThemeOnOutputRedirection: true); + applyThemeToRedirectedOutput: true); var logger = config.CreateLogger(); From dc2c98e5d6d9518641f140f510305e8fd3172c16 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Sat, 23 Nov 2019 07:41:24 +1000 Subject: [PATCH 42/85] Drop explicit private modifier --- .../ConsoleLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 01b085b..d6c2504 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -28,7 +28,7 @@ namespace Serilog /// public static class ConsoleLoggerConfigurationExtensions { - private static object DefaultSyncRoot = new object(); + static object DefaultSyncRoot = new object(); const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"; /// From 70d892be9f675b5fa122ef8a2a27102d6d27b725 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Sat, 23 Nov 2019 07:42:33 +1000 Subject: [PATCH 43/85] Incoming breaking changes --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 6c07dc5..d235962 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -1,8 +1,8 @@ - + A Serilog sink that writes log events to the console/terminal. - 3.1.2 + 4.0.0 Serilog Contributors net45;netstandard1.3;netstandard2.0;netcoreapp1.1 Serilog.Sinks.Console From 9ba137479b28834a5ec272843ff792e3a5f0ab70 Mon Sep 17 00:00:00 2001 From: James Connor Date: Sun, 12 Jan 2020 21:41:13 +0000 Subject: [PATCH 44/85] Adding netcoreapp2.0 target --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index d235962..efcf059 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -1,10 +1,10 @@ - + A Serilog sink that writes log events to the console/terminal. 4.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp1.1 + net45;netstandard1.3;netstandard2.0;netcoreapp1.1;netcoreapp2.0 Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -20,7 +20,7 @@ true true - true + true True Serilog @@ -53,5 +53,6 @@ + From 48485bcd329b57694d888b357c867b9ba52e109b Mon Sep 17 00:00:00 2001 From: Adam Chester Date: Wed, 15 Jan 2020 20:13:40 +1000 Subject: [PATCH 45/85] Stop using the alias `ls` for `Get-ChildItem` because `ls` is broken on machines that have that on the path. --- Build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build.ps1 b/Build.ps1 index 7442231..b25f8a0 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -45,7 +45,7 @@ foreach ($sample in Get-ChildItem sample/*) { Pop-Location } -foreach ($test in ls test/*.Tests) { +foreach ($test in Get-ChildItem test/*.Tests) { Push-Location $test Write-Host "build: Testing project in $test" From 4ea1e0498b7cc5b4199f6fbd9692870f30eb4045 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 16 Jul 2020 19:46:34 -0700 Subject: [PATCH 46/85] Initial nullable reference support --- .../ConsoleLoggerConfigurationExtensions.cs | 19 ++++++++++--------- .../Serilog.Sinks.Console.csproj | 10 +++++++--- .../Formatting/ThemedDisplayValueFormatter.cs | 6 +++--- .../Formatting/ThemedJsonValueFormatter.cs | 4 ++-- .../Formatting/ThemedValueFormatter.cs | 2 +- .../Formatting/ThemedValueFormatterState.cs | 2 +- .../Output/EventPropertyTokenRenderer.cs | 4 ++-- .../SystemConsole/Output/LevelOutputFormat.cs | 2 +- .../Output/LevelTokenRenderer.cs | 4 ---- .../MessageTemplateOutputTokenRenderer.cs | 3 ++- .../Output/OutputTemplateRenderer.cs | 3 ++- .../Output/PropertiesTokenRenderer.cs | 3 ++- .../Output/TimestampTokenRenderer.cs | 4 ++-- .../Sinks/SystemConsole/Rendering/Casing.cs | 2 +- .../ThemedMessageTemplateRenderer.cs | 5 +++-- .../Serilog.Sinks.Console.Tests.csproj | 5 +++++ 16 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index fa6a352..636967b 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -28,7 +28,7 @@ namespace Serilog /// public static class ConsoleLoggerConfigurationExtensions { - static object DefaultSyncRoot = new object(); + static readonly object DefaultSyncRoot = new object(); const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"; /// @@ -54,12 +54,12 @@ public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, string outputTemplate = DefaultConsoleOutputTemplate, - IFormatProvider formatProvider = null, - LoggingLevelSwitch levelSwitch = null, + IFormatProvider? formatProvider = null, + LoggingLevelSwitch? levelSwitch = null, LogEventLevel? standardErrorFromLevel = null, - ConsoleTheme theme = null, + ConsoleTheme? theme = null, bool applyThemeToRedirectedOutput = false, - object syncRoot = null) + object? syncRoot = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); @@ -68,7 +68,7 @@ public static LoggerConfiguration Console( ConsoleTheme.None : theme ?? SystemConsoleThemes.Literate; - syncRoot = syncRoot ?? DefaultSyncRoot; + syncRoot ??= DefaultSyncRoot; var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider); return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); @@ -93,14 +93,15 @@ public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, ITextFormatter formatter, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - LoggingLevelSwitch levelSwitch = null, + LoggingLevelSwitch? levelSwitch = null, LogEventLevel? standardErrorFromLevel = null, - object syncRoot = null) + object? syncRoot = null) { if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); if (formatter == null) throw new ArgumentNullException(nameof(formatter)); - syncRoot = syncRoot ?? DefaultSyncRoot; + syncRoot ??= DefaultSyncRoot; + return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); } } diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index efcf059..35588b9 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -4,7 +4,7 @@ A Serilog sink that writes log events to the console/terminal. 4.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp1.1;netcoreapp2.0 + net45;netstandard1.3;netstandard2.0;netcoreapp1.1;netcoreapp2.0; Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -26,6 +26,11 @@ Serilog + + 8.0 + enable + + $(DefineConstants);PINVOKE @@ -53,6 +58,5 @@ - - + \ No newline at end of file diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs index 38ce0b7..2653f08 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs @@ -22,9 +22,9 @@ namespace Serilog.Sinks.SystemConsole.Formatting { class ThemedDisplayValueFormatter : ThemedValueFormatter { - readonly IFormatProvider _formatProvider; + readonly IFormatProvider? _formatProvider; - public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider) + public ThemedDisplayValueFormatter(ConsoleTheme theme, IFormatProvider? formatProvider) : base(theme) { _formatProvider = formatProvider; @@ -150,7 +150,7 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic return count; } - public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format) + public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string? format) { var value = scalar.Value; var count = 0; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs index 2294ea7..3a63878 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs @@ -24,9 +24,9 @@ namespace Serilog.Sinks.SystemConsole.Formatting class ThemedJsonValueFormatter : ThemedValueFormatter { readonly ThemedDisplayValueFormatter _displayFormatter; - readonly IFormatProvider _formatProvider; + readonly IFormatProvider? _formatProvider; - public ThemedJsonValueFormatter(ConsoleTheme theme, IFormatProvider formatProvider) + public ThemedJsonValueFormatter(ConsoleTheme theme, IFormatProvider? formatProvider) : base(theme) { _displayFormatter = new ThemedDisplayValueFormatter(theme, formatProvider); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs index ea780e0..34be339 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs @@ -34,7 +34,7 @@ protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref return _theme.Apply(output, style, ref invisibleCharacterCount); } - public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false) + public int Format(LogEventPropertyValue value, TextWriter output, string? format, bool literalTopLevel = false) { return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value); } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs index 5fa497e..a5f5a86 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs @@ -19,7 +19,7 @@ namespace Serilog.Sinks.SystemConsole.Formatting struct ThemedValueFormatterState { public TextWriter Output; - public string Format; + public string? Format; public bool IsTopLevel; public ThemedValueFormatterState Nest() => new ThemedValueFormatterState { Output = Output }; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs index 19233ea..3b6d7e2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -25,9 +25,9 @@ class EventPropertyTokenRenderer : OutputTemplateTokenRenderer { readonly ConsoleTheme _theme; readonly PropertyToken _token; - readonly IFormatProvider _formatProvider; + readonly IFormatProvider? _formatProvider; - public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider formatProvider) + public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme; _token = token; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs index fdeefe2..b8682a6 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs @@ -55,7 +55,7 @@ static class LevelOutputFormat new[] { "F", "FA", "FTL", "FATL" }, }; - public static string GetLevelMoniker(LogEventLevel value, string format = null) + public static string GetLevelMoniker(LogEventLevel value, string? format = null) { if (format == null || format.Length != 2 && format.Length != 3) return Casing.Format(value.ToString(), format); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs index 54f90a2..9cb9ed1 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelTokenRenderer.cs @@ -42,10 +42,6 @@ public LevelTokenRenderer(ConsoleTheme theme, PropertyToken levelToken) _levelToken = levelToken; } - protected LevelTokenRenderer() - { - } - public override void Render(LogEvent logEvent, TextWriter output) { var moniker = LevelOutputFormat.GetLevelMoniker(logEvent.Level, _levelToken.Format); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs index 6ca5fb4..a05e63d 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs @@ -28,10 +28,11 @@ class MessageTemplateOutputTokenRenderer : OutputTemplateTokenRenderer readonly PropertyToken _token; readonly ThemedMessageTemplateRenderer _renderer; - public MessageTemplateOutputTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider formatProvider) + public MessageTemplateOutputTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme ?? throw new ArgumentNullException(nameof(theme)); _token = token ?? throw new ArgumentNullException(nameof(token)); + bool isLiteral = false, isJson = false; if (token.Format != null) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs index c2ef206..85e29f0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs @@ -27,9 +27,10 @@ class OutputTemplateRenderer : ITextFormatter { readonly OutputTemplateTokenRenderer[] _renderers; - public OutputTemplateRenderer(ConsoleTheme theme, string outputTemplate, IFormatProvider formatProvider) + public OutputTemplateRenderer(ConsoleTheme theme, string outputTemplate, IFormatProvider? formatProvider) { if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); + var template = new MessageTemplateParser().Parse(outputTemplate); var renderers = new List(); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs index 8bfe16e..4c8383c 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs @@ -31,11 +31,12 @@ class PropertiesTokenRenderer : OutputTemplateTokenRenderer readonly PropertyToken _token; readonly ThemedValueFormatter _valueFormatter; - public PropertiesTokenRenderer(ConsoleTheme theme, PropertyToken token, MessageTemplate outputTemplate, IFormatProvider formatProvider) + public PropertiesTokenRenderer(ConsoleTheme theme, PropertyToken token, MessageTemplate outputTemplate, IFormatProvider? formatProvider) { _outputTemplate = outputTemplate; _theme = theme ?? throw new ArgumentNullException(nameof(theme)); _token = token ?? throw new ArgumentNullException(nameof(token)); + var isJson = false; if (token.Format != null) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs index 5eac5e2..80f76ed 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs @@ -25,9 +25,9 @@ class TimestampTokenRenderer : OutputTemplateTokenRenderer { readonly ConsoleTheme _theme; readonly PropertyToken _token; - readonly IFormatProvider _formatProvider; + readonly IFormatProvider? _formatProvider; - public TimestampTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider formatProvider) + public TimestampTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme; _token = token; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs index ea9258f..66ce179 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Casing.cs @@ -23,7 +23,7 @@ static class Casing /// Provided string for formatting. /// Format string. /// The provided with formatting applied. - public static string Format(string value, string format = null) + public static string Format(string value, string? format = null) { switch (format) { diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs index 3d16ee0..a9d82ed 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs @@ -102,11 +102,12 @@ int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary= pt.Alignment.Value.Width) { return RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format); @@ -123,7 +124,7 @@ int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, Lo return RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format); } - int RenderValue(ConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format) + int RenderValue(ConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string? format) { if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string) { diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 77929eb..8c27464 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -16,6 +16,11 @@ true + + From 503e7aa2d1b1e91c5917cc605b1cb5a6a8fc3070 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 16 Jul 2020 19:48:38 -0700 Subject: [PATCH 47/85] Add nullable reference support to test Project --- .../Serilog.Sinks.Console.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 8c27464..868b28b 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -16,10 +16,10 @@ true - + From ccbd4d23447d5abb522076eabf32ed7bf1c2eb79 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 18:48:54 -0700 Subject: [PATCH 48/85] Update Nullable --- .../Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs | 2 +- .../Output/OutputTemplateRendererTests.cs | 8 ++++---- .../Rendering/ThemedMessageTemplateRendererTests.cs | 6 ++++-- .../Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs index 31aa4c2..eb96ae1 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs @@ -38,7 +38,7 @@ public override void Render(LogEvent logEvent, TextWriter output) return; var lines = new StringReader(logEvent.Exception.ToString()); - string nextLine; + string? nextLine; while ((nextLine = lines.ReadLine()) != null) { var style = nextLine.StartsWith(StackFrameLinePrefix) ? ConsoleThemeStyle.SecondaryText : ConsoleThemeStyle.Text; diff --git a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs index 4857999..1a71415 100644 --- a/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Output/OutputTemplateRendererTests.cs @@ -166,12 +166,12 @@ public SizeFormatter(IFormatProvider innerFormatProvider) _innerFormatProvider = innerFormatProvider; } - public object GetFormat(Type formatType) + public object? GetFormat(Type? formatType) { - return formatType == typeof(ICustomFormatter) ? this : _innerFormatProvider.GetFormat(formatType); + return formatType == typeof(ICustomFormatter) ? this : _innerFormatProvider.GetFormat(formatType) ?? this; } - public string Format(string format, object arg, IFormatProvider formatProvider) + public string Format(string? format, object? arg, IFormatProvider? formatProvider) { if (arg is Size size) return size == Size.Large ? "Huge" : size.ToString(); @@ -179,7 +179,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider) if (arg is IFormattable formattable) return formattable.ToString(format, _innerFormatProvider); - return arg.ToString(); + return arg?.ToString() ?? ""; } } diff --git a/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs b/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs index 2144cea..031f118 100644 --- a/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs +++ b/test/Serilog.Sinks.Console.Tests/Rendering/ThemedMessageTemplateRendererTests.cs @@ -121,10 +121,12 @@ static string Render(string messageTemplate, params object[] properties) return Render(null, messageTemplate, properties); } - static string Render(IFormatProvider formatProvider, string messageTemplate, params object[] properties) + static string Render(IFormatProvider? formatProvider, string messageTemplate, params object[] properties) { var binder = new LoggerConfiguration().CreateLogger(); - binder.BindMessageTemplate(messageTemplate, properties, out var mt, out var props); + if (binder.BindMessageTemplate(messageTemplate, properties, out var mt, out var props) == false) + throw new InvalidOperationException(); + var output = new StringBuilder(); var writer = new StringWriter(output); var renderer = new ThemedMessageTemplateRenderer(ConsoleTheme.None, diff --git a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs index 35faf1b..1863a41 100644 --- a/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs +++ b/test/Serilog.Sinks.Console.Tests/Support/DelegatingSink.cs @@ -20,14 +20,14 @@ public void Emit(LogEvent logEvent) public static LogEvent GetLogEvent(Action writeAction) { - LogEvent result = null; + LogEvent? result = null; var logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Sink(new DelegatingSink(le => result = le)) .CreateLogger(); writeAction(logger); - return result; + return result!; } } } From 6d36dc71bda839c71f17139004dde9ca820ca42c Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 21:03:30 -0700 Subject: [PATCH 49/85] Update Nullable --- .../SystemConsole/Formatting/ThemedJsonValueFormatter.cs | 4 ++-- .../Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs index 3a63878..6203cf5 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs @@ -154,7 +154,7 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic : ConsoleThemeStyle.Scalar; using (ApplyStyle(state.Output, style, ref count)) - JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString(), state.Output); + JsonValueFormatter.WriteQuotedJsonString((element.Key.Value?.ToString() ?? "null"), state.Output); using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(": "); @@ -248,7 +248,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output) } using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) - JsonValueFormatter.WriteQuotedJsonString(value.ToString(), output); + JsonValueFormatter.WriteQuotedJsonString(value.ToString() ?? "null", output); return count; } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs index 3b6d7e2..b2c45fd 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -62,7 +62,7 @@ public override void Render(LogEvent logEvent, TextWriter output) if (_token.Alignment.HasValue) { - var str = writer.ToString(); + var str = writer.ToString() ?? throw new InvalidOperationException("The output TextWriter, return a invalid state."); Padding.Apply(output, str, _token.Alignment); } } From 9e188c5c1a5efb49c37b1b28a5fe8d8d4bad71d6 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 21:40:11 -0700 Subject: [PATCH 50/85] Add more XML Documentation --- .../ConsoleLoggerConfigurationExtensions.cs | 4 ++++ .../Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs | 4 ++-- .../Sinks/SystemConsole/Themes/SystemConsoleTheme.cs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index fa6a352..6d4fa74 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -50,6 +50,8 @@ public static class ConsoleLoggerConfigurationExtensions /// uses . /// Applies the selected or default theme even when output redirection is detected. /// Configuration object allowing method chaining. + /// When is null + /// When is null public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, @@ -89,6 +91,8 @@ public static LoggerConfiguration Console( /// to be changed at runtime. /// Specifies the level at which events will be written to standard error. /// Configuration object allowing method chaining. + /// When is null + /// When is null public static LoggerConfiguration Console( this LoggerSinkConfiguration sinkConfiguration, ITextFormatter formatter, diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index 3ff6ce8..5809b65 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -47,10 +47,10 @@ public class AnsiConsoleTheme : ConsoleTheme /// Construct a theme given a set of styles. /// /// Styles to apply within the theme. + /// When is null public AnsiConsoleTheme(IReadOnlyDictionary styles) { - if (styles == null) throw new ArgumentNullException(nameof(styles)); - _styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); + _styles = styles?.ToDictionary(kv => kv.Key, kv => kv.Value) ?? throw new ArgumentNullException(nameof(styles)); } /// diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index 5eaf7d8..ce78587 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -44,10 +44,10 @@ public class SystemConsoleTheme : ConsoleTheme /// Construct a theme given a set of styles. /// /// Styles to apply within the theme. + /// When is null public SystemConsoleTheme(IReadOnlyDictionary styles) { - if (styles == null) throw new ArgumentNullException(nameof(styles)); - Styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); + Styles = styles?.ToDictionary(kv => kv.Key, kv => kv.Value) ?? throw new ArgumentNullException(nameof(styles)); } /// From cbccb7511bbfad0932fe77199743c8248345b046 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 21:51:20 -0700 Subject: [PATCH 51/85] Use faster null check --- .../ConsoleLoggerConfigurationExtensions.cs | 8 ++++---- .../Sinks/SystemConsole/ConsoleSink.cs | 2 +- .../Formatting/ThemedDisplayValueFormatter.cs | 6 +++--- .../SystemConsole/Formatting/ThemedJsonValueFormatter.cs | 2 +- .../Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs | 2 +- .../Sinks/SystemConsole/Output/LevelOutputFormat.cs | 2 +- .../Output/MessageTemplateOutputTokenRenderer.cs | 2 +- .../Sinks/SystemConsole/Output/OutputTemplateRenderer.cs | 6 +++--- .../Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs | 2 +- .../Sinks/SystemConsole/Output/TimestampTokenRenderer.cs | 2 +- .../Sinks/SystemConsole/Rendering/Padding.cs | 2 +- .../Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs | 2 +- .../Sinks/SystemConsole/Themes/SystemConsoleTheme.cs | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index fa6a352..2786dbd 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -61,8 +61,8 @@ public static LoggerConfiguration Console( bool applyThemeToRedirectedOutput = false, object syncRoot = null) { - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); + if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration)); + if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate)); var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ? ConsoleTheme.None : @@ -97,8 +97,8 @@ public static LoggerConfiguration Console( LogEventLevel? standardErrorFromLevel = null, object syncRoot = null) { - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); - if (formatter == null) throw new ArgumentNullException(nameof(formatter)); + if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration)); + if (formatter is null) throw new ArgumentNullException(nameof(formatter)); syncRoot = syncRoot ?? DefaultSyncRoot; return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs index bbe09e0..e1c1bea 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/ConsoleSink.cs @@ -79,7 +79,7 @@ public void Emit(LogEvent logEvent) TextWriter SelectOutputStream(LogEventLevel logEventLevel) { - if (_standardErrorFromLevel == null) + if (_standardErrorFromLevel is null) return Console.Out; return logEventLevel < _standardErrorFromLevel ? Console.Out : Console.Error; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs index 38ce0b7..b072707 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs @@ -37,14 +37,14 @@ public override ThemedValueFormatter SwitchTheme(ConsoleTheme theme) protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar) { - if (scalar == null) + if (scalar is null) throw new ArgumentNullException(nameof(scalar)); return FormatLiteralValue(scalar, state.Output, state.Format); } protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence) { - if (sequence == null) + if (sequence is null) throw new ArgumentNullException(nameof(sequence)); var count = 0; @@ -155,7 +155,7 @@ public int FormatLiteralValue(ScalarValue scalar, TextWriter output, string form var value = scalar.Value; var count = 0; - if (value == null) + if (value is null) { using (ApplyStyle(output, ConsoleThemeStyle.Null, ref count)) output.Write("null"); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs index 2294ea7..95c7d5c 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs @@ -40,7 +40,7 @@ public override ThemedValueFormatter SwitchTheme(ConsoleTheme theme) protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar) { - if (scalar == null) + if (scalar is null) throw new ArgumentNullException(nameof(scalar)); // At the top level, for scalar values, use "display" rendering. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs index 31aa4c2..eb8339f 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs @@ -34,7 +34,7 @@ public override void Render(LogEvent logEvent, TextWriter output) { // Padding is never applied by this renderer. - if (logEvent.Exception == null) + if (logEvent.Exception is null) return; var lines = new StringReader(logEvent.Exception.ToString()); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs index fdeefe2..d870705 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs @@ -57,7 +57,7 @@ static class LevelOutputFormat public static string GetLevelMoniker(LogEventLevel value, string format = null) { - if (format == null || format.Length != 2 && format.Length != 3) + if (format is null || format.Length != 2 && format.Length != 3) return Casing.Format(value.ToString(), format); // Using int.Parse() here requires allocating a string to exclude the first character prefix. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs index 6ca5fb4..90e81e0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/MessageTemplateOutputTokenRenderer.cs @@ -54,7 +54,7 @@ public MessageTemplateOutputTokenRenderer(ConsoleTheme theme, PropertyToken toke public override void Render(LogEvent logEvent, TextWriter output) { - if (_token.Alignment == null || !_theme.CanBuffer) + if (_token.Alignment is null || !_theme.CanBuffer) { _renderer.Render(logEvent.MessageTemplate, logEvent.Properties, output); return; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs index c2ef206..60aaed5 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/OutputTemplateRenderer.cs @@ -29,7 +29,7 @@ class OutputTemplateRenderer : ITextFormatter public OutputTemplateRenderer(ConsoleTheme theme, string outputTemplate, IFormatProvider formatProvider) { - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); + if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate)); var template = new MessageTemplateParser().Parse(outputTemplate); var renderers = new List(); @@ -77,8 +77,8 @@ public OutputTemplateRenderer(ConsoleTheme theme, string outputTemplate, IFormat public void Format(LogEvent logEvent, TextWriter output) { - if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); - if (output == null) throw new ArgumentNullException(nameof(output)); + if (logEvent is null) throw new ArgumentNullException(nameof(logEvent)); + if (output is null) throw new ArgumentNullException(nameof(output)); foreach (var renderer in _renderers) renderer.Render(logEvent, output); diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs index 8bfe16e..62b84b7 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/PropertiesTokenRenderer.cs @@ -61,7 +61,7 @@ public override void Render(LogEvent logEvent, TextWriter output) var value = new StructureValue(included); - if (_token.Alignment == null || !_theme.CanBuffer) + if (_token.Alignment is null || !_theme.CanBuffer) { _valueFormatter.Format(value, output, null); return; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs index 5eac5e2..671fb65 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/TimestampTokenRenderer.cs @@ -43,7 +43,7 @@ public override void Render(LogEvent logEvent, TextWriter output) var _ = 0; using (_theme.Apply(output, ConsoleThemeStyle.SecondaryText, ref _)) { - if (_token.Alignment == null) + if (_token.Alignment is null) { sv.Render(output, _token.Format, _formatProvider); } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs index cd98433..12d2595 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/Padding.cs @@ -29,7 +29,7 @@ static class Padding /// The alignment settings to apply when rendering . public static void Apply(TextWriter output, string value, Alignment? alignment) { - if (alignment == null || value.Length >= alignment.Value.Width) + if (alignment is null || value.Length >= alignment.Value.Width) { output.Write(value); return; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index 3ff6ce8..292590a 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -49,7 +49,7 @@ public class AnsiConsoleTheme : ConsoleTheme /// Styles to apply within the theme. public AnsiConsoleTheme(IReadOnlyDictionary styles) { - if (styles == null) throw new ArgumentNullException(nameof(styles)); + if (styles is null) throw new ArgumentNullException(nameof(styles)); _styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index 5eaf7d8..bfec793 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -46,7 +46,7 @@ public class SystemConsoleTheme : ConsoleTheme /// Styles to apply within the theme. public SystemConsoleTheme(IReadOnlyDictionary styles) { - if (styles == null) throw new ArgumentNullException(nameof(styles)); + if (styles is null) throw new ArgumentNullException(nameof(styles)); Styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); } From 3e849e45c99c8f50b1ac3523ab29f79e05751fbc Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 22:47:52 -0700 Subject: [PATCH 52/85] Force SyncRoot be readonly --- .../ConsoleLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 2786dbd..390b174 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -28,7 +28,7 @@ namespace Serilog /// public static class ConsoleLoggerConfigurationExtensions { - static object DefaultSyncRoot = new object(); + static readonly object DefaultSyncRoot = new object(); const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"; /// From 11bf0f4dc734103766974c38bbd792219c66e075 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Fri, 17 Jul 2020 22:51:38 -0700 Subject: [PATCH 53/85] Rollback Change --- .../ConsoleLoggerConfigurationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs index 636967b..a8d27e6 100644 --- a/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs @@ -28,7 +28,7 @@ namespace Serilog /// public static class ConsoleLoggerConfigurationExtensions { - static readonly object DefaultSyncRoot = new object(); + static object DefaultSyncRoot = new object(); const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"; /// From 2fe1f53e99d3629c09a0647f244bcdec9f1b5fbb Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Sun, 19 Jul 2020 20:30:52 -0700 Subject: [PATCH 54/85] Update Nullable Support --- .../Serilog.Sinks.Console.csproj | 12 +- .../Support/NullableAttributes..cs | 140 ++++++++++++++++++ 2 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 src/Serilog.Sinks.Console/Support/NullableAttributes..cs diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 35588b9..b963ee6 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -4,7 +4,7 @@ A Serilog sink that writes log events to the console/terminal. 4.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp1.1;netcoreapp2.0; + net45;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp1.1;netcoreapp2.0;netcoreapp3.0;netcoreapp3.1; Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -20,7 +20,7 @@ true true - true + true True Serilog @@ -34,8 +34,8 @@ $(DefineConstants);PINVOKE - - + + $(DefineConstants);PINVOKE;RUNTIME_INFORMATION @@ -49,11 +49,11 @@ - + - + diff --git a/src/Serilog.Sinks.Console/Support/NullableAttributes..cs b/src/Serilog.Sinks.Console/Support/NullableAttributes..cs new file mode 100644 index 0000000..c7a2018 --- /dev/null +++ b/src/Serilog.Sinks.Console/Support/NullableAttributes..cs @@ -0,0 +1,140 @@ +#pragma warning disable MA0048 // File name must match type name +#define INTERNAL_NULLABLE_ATTRIBUTES +#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETSTANDARD2_0 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 + +// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Diagnostics.CodeAnalysis +{ + /// Specifies that null is allowed as an input even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class AllowNullAttribute : Attribute + { } + + /// Specifies that null is disallowed as an input even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DisallowNullAttribute : Attribute + { } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullAttribute : Attribute + { } + + /// Specifies that an output will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullAttribute : Attribute + { } + + /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter may be null. + /// + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; + + /// Gets the associated parameter name. + public string ParameterName { get; } + } + + /// Applied to a method that will never return under any circumstance. + [AttributeUsage(AttributeTargets.Method, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnAttribute : Attribute + { } + + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnIfAttribute : Attribute + { + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } + } +} +#endif From 05eeca9952532436941e9bc628cff3c18ec01b43 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Sun, 19 Jul 2020 20:31:24 -0700 Subject: [PATCH 55/85] Test in all Frameworks --- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 868b28b..7c52a86 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp2.2 + net452;net462;net472;net48;netcoreapp1.1;netcoreapp2.2;netcoreapp3.1 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true From 7201374c9b7c0ef47e5bcf22aad0c0ad3d80f2e3 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Tue, 21 Jul 2020 23:36:23 -0700 Subject: [PATCH 56/85] Update appveyor config --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 728f79a..8de413c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: '{build}' skip_tags: true -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: Release test: off build_script: From 0aa42373dedc44fd7922b214d311c053e86a2d47 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 00:52:42 -0700 Subject: [PATCH 57/85] Update Test Project --- .../Serilog.Sinks.Console.Tests.csproj | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 7c52a86..58c7ec6 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net452;net462;net472;net48;netcoreapp1.1;netcoreapp2.2;netcoreapp3.1 + net452;net462;net472;net48;netcoreapp2.2;netcoreapp3.1 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true @@ -26,10 +26,13 @@ - - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + From 65ce4a1d7a583e6847006df3664454afd79cf17f Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 23:33:50 -0700 Subject: [PATCH 58/85] Rollback Refactor --- .../Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs | 3 ++- .../Sinks/SystemConsole/Themes/SystemConsoleTheme.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index 5809b65..3b80f53 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -50,7 +50,8 @@ public class AnsiConsoleTheme : ConsoleTheme /// When is null public AnsiConsoleTheme(IReadOnlyDictionary styles) { - _styles = styles?.ToDictionary(kv => kv.Key, kv => kv.Value) ?? throw new ArgumentNullException(nameof(styles)); + if (styles == null) throw new ArgumentNullException(nameof(styles)); + _styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); } /// diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index ce78587..9618f18 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -47,7 +47,8 @@ public class SystemConsoleTheme : ConsoleTheme /// When is null public SystemConsoleTheme(IReadOnlyDictionary styles) { - Styles = styles?.ToDictionary(kv => kv.Key, kv => kv.Value) ?? throw new ArgumentNullException(nameof(styles)); + if (styles == null) throw new ArgumentNullException(nameof(styles)); + Styles = styles.ToDictionary(kv => kv.Key, kv => kv.Value); } /// From 32763e5e813b56900b971b88b2f910f20e294597 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 23:51:41 -0700 Subject: [PATCH 59/85] Fix DefineConstants --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index b963ee6..a10eae9 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -35,7 +35,7 @@ $(DefineConstants);PINVOKE - + $(DefineConstants);PINVOKE;RUNTIME_INFORMATION From 75b5b76f7f84f6ae148e311d78b96407b64c95d7 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 23:52:24 -0700 Subject: [PATCH 60/85] Code rearange --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index a10eae9..79ebe33 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -5,6 +5,8 @@ 4.0.0 Serilog Contributors net45;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp1.1;netcoreapp2.0;netcoreapp3.0;netcoreapp3.1; + 8.0 + enable Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -26,10 +28,6 @@ Serilog - - 8.0 - enable - $(DefineConstants);PINVOKE From 489aaedb703abaf697058dc05b1d1294f6321372 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 23:55:07 -0700 Subject: [PATCH 61/85] Prefer to use Bang operator --- .../Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs index b2c45fd..d4fe511 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -62,7 +62,7 @@ public override void Render(LogEvent logEvent, TextWriter output) if (_token.Alignment.HasValue) { - var str = writer.ToString() ?? throw new InvalidOperationException("The output TextWriter, return a invalid state."); + var str = writer.ToString()!; Padding.Apply(output, str, _token.Alignment); } } From 642c8176a9be99cbbfff333c66d63d38b508e91d Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 22 Jul 2020 23:56:20 -0700 Subject: [PATCH 62/85] Changing error message --- .../SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs index a9d82ed..c4ef9f1 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs @@ -102,7 +102,7 @@ int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary Date: Wed, 29 Jul 2020 23:44:38 -0700 Subject: [PATCH 63/85] Change the behaver when ToString() return null. --- .../SystemConsole/Formatting/ThemedJsonValueFormatter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs index 4591333..ec6d5d1 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs @@ -154,7 +154,7 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic : ConsoleThemeStyle.Scalar; using (ApplyStyle(state.Output, style, ref count)) - JsonValueFormatter.WriteQuotedJsonString((element.Key.Value?.ToString() ?? "null"), state.Output); + JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString() ?? "", state.Output); using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count)) state.Output.Write(": "); @@ -248,7 +248,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output) } using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count)) - JsonValueFormatter.WriteQuotedJsonString(value.ToString() ?? "null", output); + JsonValueFormatter.WriteQuotedJsonString(value.ToString() ?? "", output); return count; } From 31f5aec41f9b4dff1c1c4b027b7caac61b67a44d Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 30 Jul 2020 23:58:48 -0700 Subject: [PATCH 64/85] Remove unnecessary references --- .../Serilog.Sinks.Console.csproj | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index efcf059..5702538 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -26,33 +26,16 @@ Serilog - + $(DefineConstants);PINVOKE - - $(DefineConstants);PINVOKE;RUNTIME_INFORMATION + + $(DefineConstants);RUNTIME_INFORMATION - - - - - - - - - - - - - - - - - From ba18b1948d28b87bf5af8f31673a08a2f0a64881 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Thu, 30 Jul 2020 23:59:25 -0700 Subject: [PATCH 65/85] Add More TargetFrameworks Update References Cleanup References --- sample/ConsoleDemo/ConsoleDemo.csproj | 2 +- .../Serilog.Sinks.Console.Tests.csproj | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sample/ConsoleDemo/ConsoleDemo.csproj b/sample/ConsoleDemo/ConsoleDemo.csproj index f755c4b..53ce9d8 100644 --- a/sample/ConsoleDemo/ConsoleDemo.csproj +++ b/sample/ConsoleDemo/ConsoleDemo.csproj @@ -2,7 +2,7 @@ Exe - net45;netcoreapp2.2 + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index 77929eb..c95aa2b 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,7 +1,7 @@  - net461;netcoreapp2.2 + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 Serilog.Sinks.SystemConsole.Tests Serilog.Sinks.Console.Tests true @@ -21,10 +21,13 @@ - - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + From 3caf0efd0b02934b862dc4b1db7c793a016c51ad Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 5 Aug 2020 00:03:31 -0700 Subject: [PATCH 66/85] Update Package --- .../Serilog.Sinks.Console.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index c95aa2b..3ef6d9e 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -22,7 +22,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 407285e825bc2bbe89c7e9b38245c5f7b80ef8ff Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 5 Aug 2020 00:22:52 -0700 Subject: [PATCH 67/85] Remove PINVOKE Constants --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 8 ++------ .../Sinks/SystemConsole/Platform/WindowsConsole.cs | 9 +-------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 5702538..da0d3f4 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -4,7 +4,7 @@ A Serilog sink that writes log events to the console/terminal. 4.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0;netcoreapp1.1;netcoreapp2.0 + net45;netstandard1.3;netstandard2.0; Serilog.Sinks.Console ../../assets/Serilog.snk true @@ -20,16 +20,12 @@ true true - true + true True Serilog - - $(DefineConstants);PINVOKE - - $(DefineConstants);RUNTIME_INFORMATION diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs index 05c27b2..0e8f598 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if PINVOKE using System; using System.Runtime.InteropServices; -#endif namespace Serilog.Sinks.SystemConsole.Platform { static class WindowsConsole { -#if PINVOKE public static void EnableVirtualTerminalProcessing() { #if RUNTIME_INFORMATION @@ -50,10 +47,6 @@ public static void EnableVirtualTerminalProcessing() [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetConsoleMode(IntPtr handle, uint mode); -#else - public static void EnableVirtualTerminalProcessing() - { - } -#endif + } } From 64a5a03ce8e1931372b1fab8d0b20c22b9e91e27 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 5 Aug 2020 01:02:03 -0700 Subject: [PATCH 68/85] Update Buld Script and Appveyor --- Build.ps1 | 17 ++++++++++------- appveyor.yml | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index b25f8a0..5d78e09 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,9 +1,12 @@ -Write-Host "build: Build started" +Write-Output "build: Build started" + +& dotnet --info +& dotnet --list-sdks Push-Location $PSScriptRoot if(Test-Path .\artifacts) { - Write-Host "build: Cleaning .\artifacts" + Write-Output "build: Cleaning .\artifacts" Remove-Item .\artifacts -Force -Recurse } @@ -15,13 +18,13 @@ $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch $commitHash = $(git rev-parse --short HEAD) $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] -Write-Host "build: Package version suffix is $suffix" -Write-Host "build: Build version suffix is $buildSuffix" +Write-Output "build: Package version suffix is $suffix" +Write-Output "build: Build version suffix is $buildSuffix" foreach ($src in Get-ChildItem src/*) { Push-Location $src - Write-Host "build: Packaging project in $src" + Write-Output "build: Packaging project in $src" & dotnet build -c Release --version-suffix=$buildSuffix if ($suffix) { @@ -37,7 +40,7 @@ foreach ($src in Get-ChildItem src/*) { foreach ($sample in Get-ChildItem sample/*) { Push-Location $sample - Write-Host "build: Testing project in $sample" + Write-Output "build: Testing project in $sample" & dotnet build -c Release --version-suffix=$buildSuffix if($LASTEXITCODE -ne 0) { exit 3 } @@ -48,7 +51,7 @@ foreach ($sample in Get-ChildItem sample/*) { foreach ($test in Get-ChildItem test/*.Tests) { Push-Location $test - Write-Host "build: Testing project in $test" + Write-Output "build: Testing project in $test" & dotnet test -c Release if($LASTEXITCODE -ne 0) { exit 3 } diff --git a/appveyor.yml b/appveyor.yml index 728f79a..3b7ecfc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,8 @@ version: '{build}' skip_tags: true -image: Visual Studio 2017 +image: + - Visual Studio 2019 + - Ubuntu configuration: Release test: off build_script: From ae71432905672b1e924e7a29c736df17782272f4 Mon Sep 17 00:00:00 2001 From: Rafael Cordeiro Date: Wed, 5 Aug 2020 01:17:06 -0700 Subject: [PATCH 69/85] Update Buld Script and Appveyor --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 3b7ecfc..1adfb91 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,6 @@ version: '{build}' skip_tags: true image: - Visual Studio 2019 - - Ubuntu configuration: Release test: off build_script: From 9f2694789f3c2085b4dcf598c1beae4fd45500ef Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 13 Jul 2021 09:02:47 +1000 Subject: [PATCH 70/85] Tidy up, fix build, add net5.0 targets, use the Nullable support package --- .../.idea/.gitignore | 13 ++ .../.idea/encodings.xml | 4 + .../.idea/indexLayout.xml | 8 + .../.idea.serilog-sinks-console/.idea/vcs.xml | 6 + Build.ps1 | 2 +- README.md | 20 +-- appveyor.yml | 7 +- assets/icon.png | Bin 0 -> 20352 bytes sample/ConsoleDemo/ConsoleDemo.csproj | 2 +- sample/ConsoleDemo/Program.cs | 2 +- sample/SyncWritesDemo/Program.cs | 2 +- sample/SyncWritesDemo/SyncWritesDemo.csproj | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Serilog.Sinks.Console.csproj | 18 +-- .../SystemConsole/Platform/WindowsConsole.cs | 1 - .../Support/NullableAttributes..cs | 140 ------------------ .../Properties/AssemblyInfo.cs | 19 --- .../Serilog.Sinks.Console.Tests.csproj | 18 +-- 18 files changed, 60 insertions(+), 206 deletions(-) create mode 100644 .idea/.idea.serilog-sinks-console/.idea/.gitignore create mode 100644 .idea/.idea.serilog-sinks-console/.idea/encodings.xml create mode 100644 .idea/.idea.serilog-sinks-console/.idea/indexLayout.xml create mode 100644 .idea/.idea.serilog-sinks-console/.idea/vcs.xml create mode 100644 assets/icon.png delete mode 100644 src/Serilog.Sinks.Console/Support/NullableAttributes..cs delete mode 100644 test/Serilog.Sinks.Console.Tests/Properties/AssemblyInfo.cs diff --git a/.idea/.idea.serilog-sinks-console/.idea/.gitignore b/.idea/.idea.serilog-sinks-console/.idea/.gitignore new file mode 100644 index 0000000..c239f02 --- /dev/null +++ b/.idea/.idea.serilog-sinks-console/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/.idea.serilog-sinks-console.iml +/modules.xml +/projectSettingsUpdater.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.idea.serilog-sinks-console/.idea/encodings.xml b/.idea/.idea.serilog-sinks-console/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.serilog-sinks-console/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-sinks-console/.idea/indexLayout.xml b/.idea/.idea.serilog-sinks-console/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.serilog-sinks-console/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-sinks-console/.idea/vcs.xml b/.idea/.idea.serilog-sinks-console/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.serilog-sinks-console/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Build.ps1 b/Build.ps1 index 5d78e09..b0ac93a 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -14,7 +14,7 @@ if(Test-Path .\artifacts) { $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] $commitHash = $(git rev-parse --short HEAD) $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] diff --git a/README.md b/README.md index b1996b3..b380b56 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ A Serilog sink that writes log events to the Windows Console or an ANSI terminal To use the console sink, first install the [NuGet package](https://nuget.org/packages/serilog.sinks.console): -```powershell -Install-Package Serilog.Sinks.Console +```shell +dotnet add package Serilog.Sinks.Console ``` Then enable the sink using `WriteTo.Console()`: @@ -64,8 +64,8 @@ The default template, shown in the example above, uses built-in properties like 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: -```powershell -Install-Package Serilog.Formatting.Compact +```shell +dotnet add package Serilog.Formatting.Compact ``` Pass a formatter to the `Console()` configuration method: @@ -80,8 +80,8 @@ Output theming is not available when custom formatters are used. To use the console sink with the [Serilog.Settings.AppSettings](https://github.com/serilog/serilog-settings-appsettings) package, first install that package if you haven't already done so: -```powershell -Install-Package Serilog.Settings.AppSettings +```shell +dotnet add package Serilog.Settings.AppSettings ``` Instead of configuring the logger in code, call `ReadFrom.AppSettings()`: @@ -114,8 +114,8 @@ To configure the console sink with a different theme and include the `SourceCont To use the console sink with _Microsoft.Extensions.Configuration_, for example with ASP.NET Core or .NET Core, use the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) package. First install that package if you have not already done so: -```powershell -Install-Package Serilog.Settings.Configuration +```shell +dotnet add package Serilog.Settings.Configuration ``` Instead of configuring the sink directly in code, call `ReadFrom.Configuration()`: @@ -168,7 +168,7 @@ When contributing please keep in mind our [Code of Conduct](CODE_OF_CONDUCT.md). Branch | AppVeyor | Travis ------------- | ------------- |------------- dev | [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/dev) | [![Build Status](https://travis-ci.org/serilog/serilog-sinks-console.svg?branch=dev)](https://travis-ci.org/serilog/serilog-sinks-console) -master | [![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) | [![Build Status](https://travis-ci.org/serilog/serilog-sinks-console.svg?branch=master)](https://travis-ci.org/serilog/serilog-sinks-console) +main | [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/main?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/main) | [![Build Status](https://travis-ci.org/serilog/serilog-sinks-console.svg?branch=main)](https://travis-ci.org/serilog/serilog-sinks-console) -_Copyright © 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._ +_Copyright © Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._ diff --git a/appveyor.yml b/appveyor.yml index 8de413c..3c57f91 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,6 @@ version: '{build}' skip_tags: true image: Visual Studio 2019 -configuration: Release test: off build_script: - ps: ./Build.ps1 @@ -10,14 +9,14 @@ artifacts: deploy: - provider: NuGet api_key: - secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/ + secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5 skip_symbols: true on: - branch: /^(master|dev)$/ + branch: /^(main|dev)$/ - provider: GitHub auth_token: secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX artifact: /Serilog.*\.nupkg/ tag: v$(appveyor_build_version) on: - branch: master + branch: main diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9bf45a319eec8b1a6a2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RB02sn)ZuFLN!QdTHd000205J-pv>eUB2vac6cR#t|MjScSJy(|4iA~6)D1?%bQ zNp!x7iVBR3j9_bPiziQ>;K73jQuMAkd3kwAOiV;rSQwf&Z;rNY*=^Gb1OjyF(ghPI zPDEj0AyQLQrJe^dY0@ODU%#HrNI?OegP&K(QFZS9F{U$%ITM<9Y>lC={YtETU-|o6UyRYIWk1 z9;w&s7=|HL8GicsC*MzZFrVY!008*;1AhI6ta}-xq9|0WRUF6p=K_#(VcRy_?Ur)6 z{Hm8UnM|VVI?-s9>2!Mb`G@s-O~2n~x7#6va6LC4i^b41ja)9rd_F&En^09%Ow*LR z_`DwTXI7I}_fFi19=rO{}3BJVgH4$NjV z48tH2iI7gGUCTQXi3GZ?6OYHSZCl#uS11&)EK6Q^`spJKzREr04dVX*0JvMg_Wrm` zR6^M3XR*jj2#3R{s!F9&@kHM7Xd|*LOUg#1C<;Odn$0Hr{hq~Q;VRIC5R676IhzlF z@dZBrZGrwD@J|omC0ty>)ip>AwE*;bJzA}nXHEftd_K=`IFu^Sn5Idm)A6hVU8~jT zcDt^F;F0BWNxR*C)!$hvm0~;|yEY*`@$Cja_+wSK7yJQ|W-~!e-LqQ&0000P literal 0 HcmV?d00001 diff --git a/sample/ConsoleDemo/ConsoleDemo.csproj b/sample/ConsoleDemo/ConsoleDemo.csproj index 53ce9d8..81b1a1f 100644 --- a/sample/ConsoleDemo/ConsoleDemo.csproj +++ b/sample/ConsoleDemo/ConsoleDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48;net5.0 diff --git a/sample/ConsoleDemo/Program.cs b/sample/ConsoleDemo/Program.cs index 28ce01f..73d50d8 100644 --- a/sample/ConsoleDemo/Program.cs +++ b/sample/ConsoleDemo/Program.cs @@ -5,7 +5,7 @@ namespace ConsoleDemo { - public class Program + public static class Program { public static void Main() { diff --git a/sample/SyncWritesDemo/Program.cs b/sample/SyncWritesDemo/Program.cs index 07713b4..5120393 100644 --- a/sample/SyncWritesDemo/Program.cs +++ b/sample/SyncWritesDemo/Program.cs @@ -47,7 +47,7 @@ static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForL .CreateLogger(); var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; - System.Threading.Tasks.Parallel.For(0, 1000, options, (i, loopState) => + Parallel.For(0, 1000, options, (i, loopState) => { var logger = (i % 2 == 0) ? logger1 : logger2; logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId); diff --git a/sample/SyncWritesDemo/SyncWritesDemo.csproj b/sample/SyncWritesDemo/SyncWritesDemo.csproj index 169fe56..a72595e 100644 --- a/sample/SyncWritesDemo/SyncWritesDemo.csproj +++ b/sample/SyncWritesDemo/SyncWritesDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + net5.0 diff --git a/src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs index 3ecea3a..34ef2fa 100644 --- a/src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs +++ b/src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ [assembly: CLSCompliant(true)] -[assembly: InternalsVisibleTo("Serilog.Sinks.SystemConsole.Tests, PublicKey=" + +[assembly: InternalsVisibleTo("Serilog.Sinks.Console.Tests, PublicKey=" + "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 28fe20a..4a93619 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -4,25 +4,19 @@ A Serilog sink that writes log events to the console/terminal. 4.0.0 Serilog Contributors - net45;netstandard1.3;netstandard2.0; + net45;netstandard1.3;netstandard2.0;net5.0 8.0 enable - Serilog.Sinks.Console ../../assets/Serilog.snk true true - Serilog.Sinks.Console serilog;console;terminal - http://serilog.net/images/serilog-sink-nuget.png + icon.png https://github.com/serilog/serilog-sinks-console Apache-2.0 https://github.com/serilog/serilog-sinks-console git - true - true true - - true True Serilog @@ -33,7 +27,11 @@ - + + + + + + - diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs index 0e8f598..fce3ecf 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Platform/WindowsConsole.cs @@ -47,6 +47,5 @@ public static void EnableVirtualTerminalProcessing() [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetConsoleMode(IntPtr handle, uint mode); - } } diff --git a/src/Serilog.Sinks.Console/Support/NullableAttributes..cs b/src/Serilog.Sinks.Console/Support/NullableAttributes..cs deleted file mode 100644 index c7a2018..0000000 --- a/src/Serilog.Sinks.Console/Support/NullableAttributes..cs +++ /dev/null @@ -1,140 +0,0 @@ -#pragma warning disable MA0048 // File name must match type name -#define INTERNAL_NULLABLE_ATTRIBUTES -#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETSTANDARD2_0 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 - -// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Diagnostics.CodeAnalysis -{ - /// Specifies that null is allowed as an input even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class AllowNullAttribute : Attribute - { } - - /// Specifies that null is disallowed as an input even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class DisallowNullAttribute : Attribute - { } - - /// Specifies that an output may be null even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class MaybeNullAttribute : Attribute - { } - - /// Specifies that an output will not be null even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class NotNullAttribute : Attribute - { } - - /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class MaybeNullWhenAttribute : Attribute - { - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter may be null. - /// - public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } - } - - /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class NotNullWhenAttribute : Attribute - { - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } - } - - /// Specifies that the output will be non-null if the named parameter is non-null. - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class NotNullIfNotNullAttribute : Attribute - { - /// Initializes the attribute with the associated parameter name. - /// - /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. - /// - public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; - - /// Gets the associated parameter name. - public string ParameterName { get; } - } - - /// Applied to a method that will never return under any circumstance. - [AttributeUsage(AttributeTargets.Method, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class DoesNotReturnAttribute : Attribute - { } - - /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -#if INTERNAL_NULLABLE_ATTRIBUTES - internal -#else - public -#endif - sealed class DoesNotReturnIfAttribute : Attribute - { - /// Initializes the attribute with the specified parameter value. - /// - /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to - /// the associated parameter matches this value. - /// - public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; - - /// Gets the condition parameter value. - public bool ParameterValue { get; } - } -} -#endif diff --git a/test/Serilog.Sinks.Console.Tests/Properties/AssemblyInfo.cs b/test/Serilog.Sinks.Console.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 4911a24..0000000 --- a/test/Serilog.Sinks.Console.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Serilog.Sinks.Trace.Tests")] -[assembly: AssemblyTrademark("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1d56534c-4009-42c2-a573-789cae6b8aa9")] diff --git a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj index cf00377..5e141e3 100644 --- a/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj +++ b/test/Serilog.Sinks.Console.Tests/Serilog.Sinks.Console.Tests.csproj @@ -1,22 +1,11 @@ - netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48 - Serilog.Sinks.SystemConsole.Tests - Serilog.Sinks.Console.Tests + netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48;net5.0 true - 1.6.0 - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - 1.0.4 - false - false - false ../../assets/Serilog.snk true true - - - 8.0 enable @@ -27,10 +16,7 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + From 447b0b8c8a6bdc56c78f58857695ea467122150e Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 13 Jul 2021 09:13:59 +1000 Subject: [PATCH 71/85] Dev version bump [skip ci] --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index 4a93619..db06a7e 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -2,7 +2,7 @@ A Serilog sink that writes log events to the console/terminal. - 4.0.0 + 4.0.1 Serilog Contributors net45;netstandard1.3;netstandard2.0;net5.0 8.0 From 08e0e65e622a7f2e6af49a0fa12afc8ca127a4f5 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 13 Jul 2021 18:09:45 +1000 Subject: [PATCH 72/85] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 0c1a63a..5402100 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,25 +1,12 @@ -**A few questions before you begin:** +Hi 👋 -> Is this an issue related to the Serilog core project or one of the [sinks](https://github.com/serilog/serilog/wiki/Provided-Sinks) or [community projects](https://github.com/serilog/serilog/wiki/Community-Projects). This issue list is intended for Serilog core issues. If this issue relates to a sink or related project, please log on the related repository. Please use [Gitter chat](https://gitter.im/serilog/serilog) and [Stack Overflow](http://stackoverflow.com/questions/tagged/serilog) for discussions and questons. +If you have a question about using Serilog, or something isn't working as you expect it to, please post your question to the [`serilog` tag on Stack Overflow](https://stackoverflow.com/questions/tagged/serilog), where many more people are ready to help you out. +To report a bug or request a feature, please give us as much information as possible, for example: -**Does this issue relate to a new *feature* or an existing *bug*?** -- [ ] Bug -- [ ] New Feature + - [ ] the exact package id and version you're using, + - [ ] your `dotnet` toolchain version, target framework, and operating system, + - [ ] the current behavior, and + - [ ] what you expect or want to happen instead. -**What version of Serilog Console Sink is affected by this issue? Please list the related NuGet package.** - -**What is the target framework and operating system affected by this issue? Please see [target frameworks](https://docs.microsoft.com/en-us/nuget/schema/target-frameworks) & [net standard matrix](https://docs.microsoft.com/en-us/dotnet/standard/net-standard).** - -- [ ] netCore 2.0 -- [ ] netCore 1.0 -- [ ] 4.7 -- [ ] 4.6.x -- [ ] 4.5.x - -**Please describe the current behaviour you are experiencing?** - -**Please describe the expected behaviour if the ?** - -**If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem** -*NOTE: A small code sample goes a long way in expediting bug fixes or illustrating an enhancement you are proposing.* +Thanks! From 5045157e0b52c7e48482c8149cb57badaeefa275 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Fri, 30 Jul 2021 10:53:54 +0300 Subject: [PATCH 73/85] Update ThemedMessageTemplateRenderer.cs indent --- .../SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs index c4ef9f1..a299520 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs @@ -102,7 +102,7 @@ int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary Date: Thu, 7 Oct 2021 12:55:59 -0700 Subject: [PATCH 74/85] Add two new 16 color ANSI compatible themes --- README.md | 4 +- .../SystemConsole/Themes/AnsiConsoleTheme.cs | 12 +++- .../SystemConsole/Themes/AnsiConsoleThemes.cs | 63 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b380b56..734b22d 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,11 @@ 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.Literate16Color` - an ANSI 16-color version of the "literate" theme that works with light backgrounds * `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme * `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme + * `AnsiConsoleTheme.Code16Color` - an ANSI 16-color Visual Studio Code-inspired theme that works with light 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. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index ea95ee3..d6f9680 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -30,6 +30,11 @@ public class AnsiConsoleTheme : ConsoleTheme /// public static AnsiConsoleTheme Code { get; } = AnsiConsoleThemes.Code; + /// + /// A 16-color theme along the lines of Visual Studio Code that should work on light backgrounds. + /// + public static AnsiConsoleTheme Code16Color { get; } = AnsiConsoleThemes.Code16Color; + /// /// A theme using only gray, black and white. /// @@ -40,6 +45,11 @@ public class AnsiConsoleTheme : ConsoleTheme /// public static AnsiConsoleTheme Literate { get; } = AnsiConsoleThemes.Literate; + /// + /// A theme in the style of the original Serilog.Sinks.Literate using only standard 16 terminal colors that will work on light backgrounds. + /// + public static AnsiConsoleTheme Literate16Color { get; } = AnsiConsoleThemes.Literate16Color; + readonly IReadOnlyDictionary _styles; const string AnsiStyleReset = "\x1b[0m"; @@ -77,4 +87,4 @@ public override void Reset(TextWriter output) output.Write(AnsiStyleReset); } } -} \ No newline at end of file +} diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index 5cbb051..7635de9 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -18,6 +18,27 @@ namespace Serilog.Sinks.SystemConsole.Themes { static class AnsiConsoleThemes { + const string Reset = "\x1b[0m"; + const string Bold = "\x1b[1m"; + + const string Black = "\x1b[30m"; + const string Red = "\x1b[31m"; + const string Green = "\x1b[32m"; + const string Yellow = "\x1b[33m"; + const string Blue = "\x1b[34m"; + const string Magenta = "\x1b[35m"; + const string Cyan = "\x1b[36m"; + const string White = "\x1b[37m"; + + const string BrightBlack = "\x1b[30;1m"; + const string BrightRed = "\x1b[31;1m"; + const string BrightGreen = "\x1b[32;1m"; + const string BrightYellow = "\x1b[33;1m"; + const string BrightBlue = "\x1b[34;1m"; + const string BrightMagenta = "\x1b[35;1m"; + const string BrightCyan = "\x1b[36;1m"; + const string BrightWhite = "\x1b[37;1m"; + public static AnsiConsoleTheme Literate { get; } = new AnsiConsoleTheme( new Dictionary { @@ -39,6 +60,27 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", }); + public static AnsiConsoleTheme Literate16Color { get; } = new AnsiConsoleTheme( + new Dictionary + { + [ConsoleThemeStyle.Text] = Reset, + [ConsoleThemeStyle.SecondaryText] = Reset, + [ConsoleThemeStyle.TertiaryText] = Reset, + [ConsoleThemeStyle.Invalid] = Yellow, + [ConsoleThemeStyle.Null] = Blue, + [ConsoleThemeStyle.Name] = Reset, + [ConsoleThemeStyle.String] = Cyan, + [ConsoleThemeStyle.Number] = Magenta, + [ConsoleThemeStyle.Boolean] = Blue, + [ConsoleThemeStyle.Scalar] = Green, + [ConsoleThemeStyle.LevelVerbose] = Reset, + [ConsoleThemeStyle.LevelDebug] = Bold, + [ConsoleThemeStyle.LevelInformation] = BrightCyan, + [ConsoleThemeStyle.LevelWarning] = BrightYellow, + [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m", + [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", + }); + public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme( new Dictionary { @@ -80,5 +122,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 Code16Color { get; } = new AnsiConsoleTheme( + new Dictionary + { + [ConsoleThemeStyle.Text] = Reset, + [ConsoleThemeStyle.SecondaryText] = Reset, + [ConsoleThemeStyle.TertiaryText] = Reset, + [ConsoleThemeStyle.Invalid] = BrightYellow, + [ConsoleThemeStyle.Null] = Cyan, + [ConsoleThemeStyle.Name] = Cyan, + [ConsoleThemeStyle.String] = Yellow, + [ConsoleThemeStyle.Number] = BrightYellow, + [ConsoleThemeStyle.Boolean] = Cyan, + [ConsoleThemeStyle.Scalar] = Green, + [ConsoleThemeStyle.LevelVerbose] = Reset, + [ConsoleThemeStyle.LevelDebug] = Reset, + [ConsoleThemeStyle.LevelInformation] = Bold, + [ConsoleThemeStyle.LevelWarning] = BrightYellow, + [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m", + [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m", + }); } } From c3231ab4b34595cf6a09906469a4316a86d87d21 Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Wed, 20 Oct 2021 09:32:17 +0200 Subject: [PATCH 75/85] Fix ExceptionTokenRenderer to WriteLine after reset sequence --- .../Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs index b3db007..a70c161 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/ExceptionTokenRenderer.cs @@ -44,7 +44,8 @@ public override void Render(LogEvent logEvent, TextWriter output) var style = nextLine.StartsWith(StackFrameLinePrefix) ? ConsoleThemeStyle.SecondaryText : ConsoleThemeStyle.Text; var _ = 0; using (_theme.Apply(output, style, ref _)) - output.WriteLine(nextLine); + output.Write(nextLine); + output.WriteLine(); } } } From 4a76e28fd8c9c7249cbfcca7277294a26476329b Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Fri, 19 Nov 2021 10:04:44 +1000 Subject: [PATCH 76/85] Dev version bump [skip ci] --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index db06a7e..fc0e3d0 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -2,7 +2,7 @@ A Serilog sink that writes log events to the console/terminal. - 4.0.1 + 4.0.2 Serilog Contributors net45;netstandard1.3;netstandard2.0;net5.0 8.0 From 59423bd74d9192ff893ddd3c1c431ac47a9e2052 Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Tue, 14 Dec 2021 23:33:42 +0100 Subject: [PATCH 77/85] feat: add sixteen colors theme supports light terminal background --- .../SystemConsole/Themes/AnsiConsoleTheme.cs | 7 +-- .../SystemConsole/Themes/AnsiConsoleThemes.cs | 45 +++++-------------- .../Themes/SystemConsoleTheme.cs | 5 +++ .../Themes/SystemConsoleThemes.cs | 21 +++++++++ 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index d6f9680..8aefd8b 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -30,11 +30,6 @@ public class AnsiConsoleTheme : ConsoleTheme /// public static AnsiConsoleTheme Code { get; } = AnsiConsoleThemes.Code; - /// - /// A 16-color theme along the lines of Visual Studio Code that should work on light backgrounds. - /// - public static AnsiConsoleTheme Code16Color { get; } = AnsiConsoleThemes.Code16Color; - /// /// A theme using only gray, black and white. /// @@ -48,7 +43,7 @@ public class AnsiConsoleTheme : ConsoleTheme /// /// A theme in the style of the original Serilog.Sinks.Literate using only standard 16 terminal colors that will work on light backgrounds. /// - public static AnsiConsoleTheme Literate16Color { get; } = AnsiConsoleThemes.Literate16Color; + public static AnsiConsoleTheme Sixteen { get; } = AnsiConsoleThemes.Sixteen; readonly IReadOnlyDictionary _styles; const string AnsiStyleReset = "\x1b[0m"; diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index 7635de9..b40acf0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -60,27 +60,6 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", }); - public static AnsiConsoleTheme Literate16Color { get; } = new AnsiConsoleTheme( - new Dictionary - { - [ConsoleThemeStyle.Text] = Reset, - [ConsoleThemeStyle.SecondaryText] = Reset, - [ConsoleThemeStyle.TertiaryText] = Reset, - [ConsoleThemeStyle.Invalid] = Yellow, - [ConsoleThemeStyle.Null] = Blue, - [ConsoleThemeStyle.Name] = Reset, - [ConsoleThemeStyle.String] = Cyan, - [ConsoleThemeStyle.Number] = Magenta, - [ConsoleThemeStyle.Boolean] = Blue, - [ConsoleThemeStyle.Scalar] = Green, - [ConsoleThemeStyle.LevelVerbose] = Reset, - [ConsoleThemeStyle.LevelDebug] = Bold, - [ConsoleThemeStyle.LevelInformation] = BrightCyan, - [ConsoleThemeStyle.LevelWarning] = BrightYellow, - [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m", - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", - }); - public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme( new Dictionary { @@ -123,25 +102,25 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m", }); - public static AnsiConsoleTheme Code16Color { get; } = new AnsiConsoleTheme( + public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme( new Dictionary { [ConsoleThemeStyle.Text] = Reset, [ConsoleThemeStyle.SecondaryText] = Reset, [ConsoleThemeStyle.TertiaryText] = Reset, - [ConsoleThemeStyle.Invalid] = BrightYellow, - [ConsoleThemeStyle.Null] = Cyan, - [ConsoleThemeStyle.Name] = Cyan, - [ConsoleThemeStyle.String] = Yellow, - [ConsoleThemeStyle.Number] = BrightYellow, - [ConsoleThemeStyle.Boolean] = Cyan, + [ConsoleThemeStyle.Invalid] = Yellow, + [ConsoleThemeStyle.Null] = Blue, + [ConsoleThemeStyle.Name] = Reset, + [ConsoleThemeStyle.String] = Cyan, + [ConsoleThemeStyle.Number] = Magenta, + [ConsoleThemeStyle.Boolean] = Blue, [ConsoleThemeStyle.Scalar] = Green, [ConsoleThemeStyle.LevelVerbose] = Reset, - [ConsoleThemeStyle.LevelDebug] = Reset, - [ConsoleThemeStyle.LevelInformation] = Bold, + [ConsoleThemeStyle.LevelDebug] = Bold, + [ConsoleThemeStyle.LevelInformation] = BrightCyan, [ConsoleThemeStyle.LevelWarning] = BrightYellow, - [ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m", - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m", + [ConsoleThemeStyle.LevelError] = BrightRed, + [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", }); } -} +} \ No newline at end of file diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index a4518c8..1d60c67 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -39,6 +39,11 @@ public class SystemConsoleTheme : ConsoleTheme /// A theme based on the original Serilog "colored console" sink. /// public static SystemConsoleTheme Colored { get; } = SystemConsoleThemes.Colored; + + /// + /// A theme in the style of the original Serilog.Sinks.Literate using only standard 16 terminal colors that will work on light backgrounds. + /// + public static SystemConsoleTheme Sixteen { get; } = SystemConsoleThemes.Sixteen; /// /// Construct a theme given a set of styles. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs index 5e202f9..73ab8ce 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs @@ -81,5 +81,26 @@ static class SystemConsoleThemes [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, }); + + public static SystemConsoleTheme Sixteen { get; } = new SystemConsoleTheme( + new Dictionary + { + [ConsoleThemeStyle.Text] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.SecondaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.TertiaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkYellow }, + [ConsoleThemeStyle.Null] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue }, + [ConsoleThemeStyle.Name] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkCyan }, + [ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Magenta }, + [ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue }, + [ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Green }, + [ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, + [ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Cyan }, + [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow }, + [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Red, }, + [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, + }); } } From 2e4c5cfba47c4d2e534ff57e7a42d7753525d1f8 Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Tue, 14 Dec 2021 23:40:25 +0100 Subject: [PATCH 78/85] Remove newline --- .../Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs index 8aefd8b..c37942b 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs @@ -82,4 +82,4 @@ public override void Reset(TextWriter output) output.Write(AnsiStyleReset); } } -} +} \ No newline at end of file From e5e1dd50b90bf17996c266e13bad215bf4708667 Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Tue, 14 Dec 2021 23:43:48 +0100 Subject: [PATCH 79/85] amend readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 734b22d..da5fc2d 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ 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 + * `SystemConsoleTheme.Sixteen` - a version of the "literate" theme that works with light and dark backgrounds * `AnsiConsoleTheme.Literate` - an ANSI 256-color version of the "literate" theme - * `AnsiConsoleTheme.Literate16Color` - an ANSI 16-color version of the "literate" theme that works with light backgrounds * `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme * `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme - * `AnsiConsoleTheme.Code16Color` - an ANSI 16-color Visual Studio Code-inspired theme that works with light backgrounds + * `AnsiConsoleTheme.Sixteen` - an ANSI 16-color version of the "literate" theme that works with 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. From 11fe717f5bb046145a3e7a18aa6efb92cad08ade Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Tue, 21 Dec 2021 11:13:14 +0100 Subject: [PATCH 80/85] remove system sixteen --- README.md | 1 - .../Themes/SystemConsoleTheme.cs | 5 ----- .../Themes/SystemConsoleThemes.cs | 21 ------------------- 3 files changed, 27 deletions(-) diff --git a/README.md b/README.md index da5fc2d..263d303 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ 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 - * `SystemConsoleTheme.Sixteen` - a version of the "literate" theme that works with light and dark backgrounds * `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 diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs index 1d60c67..a4518c8 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs @@ -39,11 +39,6 @@ public class SystemConsoleTheme : ConsoleTheme /// A theme based on the original Serilog "colored console" sink. /// public static SystemConsoleTheme Colored { get; } = SystemConsoleThemes.Colored; - - /// - /// A theme in the style of the original Serilog.Sinks.Literate using only standard 16 terminal colors that will work on light backgrounds. - /// - public static SystemConsoleTheme Sixteen { get; } = SystemConsoleThemes.Sixteen; /// /// Construct a theme given a set of styles. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs index 73ab8ce..5e202f9 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs @@ -81,26 +81,5 @@ static class SystemConsoleThemes [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, }); - - public static SystemConsoleTheme Sixteen { get; } = new SystemConsoleTheme( - new Dictionary - { - [ConsoleThemeStyle.Text] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.SecondaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.TertiaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkYellow }, - [ConsoleThemeStyle.Null] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue }, - [ConsoleThemeStyle.Name] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkCyan }, - [ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Magenta }, - [ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue }, - [ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Green }, - [ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black }, - [ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Cyan }, - [ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow }, - [ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Red, }, - [ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red }, - }); } } From 4749eb057d47dd7b65fa1fa612306e45a85d5593 Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Tue, 21 Dec 2021 11:30:41 +0100 Subject: [PATCH 81/85] add newline back --- .../Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index b40acf0..87bee56 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -123,4 +123,4 @@ static class AnsiConsoleThemes [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", }); } -} \ No newline at end of file +} From b6a4ae6061a9b5642449852e9bc005a47460cefc Mon Sep 17 00:00:00 2001 From: Guillaume Gobbe Date: Wed, 22 Dec 2021 11:02:45 +0100 Subject: [PATCH 82/85] Fix PR comments --- README.md | 2 +- .../SystemConsole/Themes/AnsiConsoleThemes.cs | 53 ++++++------------- .../Themes/AnsiEscapeSequence.cs | 41 ++++++++++++++ 3 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs diff --git a/README.md b/README.md index 263d303..7adc13e 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The following built-in themes are available: * `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 version of the "literate" theme that works with light and dark backgrounds + * `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. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index 87bee56..1728aa0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -18,27 +18,6 @@ namespace Serilog.Sinks.SystemConsole.Themes { static class AnsiConsoleThemes { - const string Reset = "\x1b[0m"; - const string Bold = "\x1b[1m"; - - const string Black = "\x1b[30m"; - const string Red = "\x1b[31m"; - const string Green = "\x1b[32m"; - const string Yellow = "\x1b[33m"; - const string Blue = "\x1b[34m"; - const string Magenta = "\x1b[35m"; - const string Cyan = "\x1b[36m"; - const string White = "\x1b[37m"; - - const string BrightBlack = "\x1b[30;1m"; - const string BrightRed = "\x1b[31;1m"; - const string BrightGreen = "\x1b[32;1m"; - const string BrightYellow = "\x1b[33;1m"; - const string BrightBlue = "\x1b[34;1m"; - const string BrightMagenta = "\x1b[35;1m"; - const string BrightCyan = "\x1b[36;1m"; - const string BrightWhite = "\x1b[37;1m"; - public static AnsiConsoleTheme Literate { get; } = new AnsiConsoleTheme( new Dictionary { @@ -105,22 +84,22 @@ static class AnsiConsoleThemes public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme( new Dictionary { - [ConsoleThemeStyle.Text] = Reset, - [ConsoleThemeStyle.SecondaryText] = Reset, - [ConsoleThemeStyle.TertiaryText] = Reset, - [ConsoleThemeStyle.Invalid] = Yellow, - [ConsoleThemeStyle.Null] = Blue, - [ConsoleThemeStyle.Name] = Reset, - [ConsoleThemeStyle.String] = Cyan, - [ConsoleThemeStyle.Number] = Magenta, - [ConsoleThemeStyle.Boolean] = Blue, - [ConsoleThemeStyle.Scalar] = Green, - [ConsoleThemeStyle.LevelVerbose] = Reset, - [ConsoleThemeStyle.LevelDebug] = Bold, - [ConsoleThemeStyle.LevelInformation] = BrightCyan, - [ConsoleThemeStyle.LevelWarning] = BrightYellow, - [ConsoleThemeStyle.LevelError] = BrightRed, - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", + [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, }); } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs new file mode 100644 index 0000000..2512190 --- /dev/null +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs @@ -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"; + } +} \ No newline at end of file From f2351f29330fbd0a33bab62bb63b9c358adadb01 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Sat, 2 Apr 2022 06:39:35 +1000 Subject: [PATCH 83/85] Note the use of Serilog.Sinks.Async to move writes to background thread [skip ci] --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 7adc13e..b5d27bc 100644 --- a/README.md +++ b/README.md @@ -157,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). From fd86c78a6f378fd5f95c2265196ad3808f52c0dc Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 5 Sep 2022 16:18:31 +1000 Subject: [PATCH 84/85] Bump minor version - new theme added --- src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj index fc0e3d0..06abb29 100644 --- a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj @@ -2,7 +2,7 @@ A Serilog sink that writes log events to the console/terminal. - 4.0.2 + 4.1.0 Serilog Contributors net45;netstandard1.3;netstandard2.0;net5.0 8.0 From df9f28a10e7c8dab8adb11f497c69180e2394e15 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 6 Sep 2022 09:03:40 +1000 Subject: [PATCH 85/85] Update publishing key --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 3c57f91..397acc7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: '{build}' skip_tags: true -image: Visual Studio 2019 +image: Visual Studio 2022 test: off build_script: - ps: ./Build.ps1 @@ -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)$/