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 e2ea4dc..19233ea 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/EventPropertyTokenRenderer.cs @@ -37,10 +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). - LogEventPropertyValue propertyValue; - if (!logEvent.Properties.TryGetValue(_token.PropertyName, out 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..fdeefe2 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Output/LevelOutputFormat.cs @@ -25,31 +25,34 @@ 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[] { "D", "DE", "DBG", "DBUG" }, + 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 +81,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 466632d..54f90a2 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 }, @@ -32,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 9fa9ca4..3d16ee0 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 var propertyValue)) { var count = 0; using (_theme.Apply(output, ConsoleThemeStyle.Invalid, ref count)) @@ -116,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/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/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 2106801..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, @@ -75,9 +75,10 @@ public enum ConsoleThemeStyle Scalar, /// - /// Unrecogized literal values, e.g. instances. + /// 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 828cf07..5eaf7d8 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; @@ -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,22 +47,22 @@ 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; } /// public override bool CanBuffer => false; /// - protected override int ResetCharCount { get; } = 0; + protected override int ResetCharCount { get; } /// 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; 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 99a472b..35faf1b 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) @@ -22,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; } }