From 7c03a24120f91a98c8a9cfeba9d8c8d197a960c0 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Wed, 16 Mar 2016 15:51:20 +1000 Subject: [PATCH] Removed the colored console sink. --- ...redConsoleLoggerConfigurationExtensions.cs | 52 ----- .../Properties/AssemblyInfo.cs | 14 -- .../Serilog.Sinks.ColoredConsole.xproj | 18 -- .../ColoredConsole/ColoredConsoleSink.cs | 186 ------------------ src/Serilog.Sinks.ColoredConsole/project.json | 24 --- 5 files changed, 294 deletions(-) delete mode 100644 src/Serilog.Sinks.ColoredConsole/ColoredConsoleLoggerConfigurationExtensions.cs delete mode 100644 src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs delete mode 100644 src/Serilog.Sinks.ColoredConsole/Serilog.Sinks.ColoredConsole.xproj delete mode 100644 src/Serilog.Sinks.ColoredConsole/Sinks/ColoredConsole/ColoredConsoleSink.cs delete mode 100644 src/Serilog.Sinks.ColoredConsole/project.json diff --git a/src/Serilog.Sinks.ColoredConsole/ColoredConsoleLoggerConfigurationExtensions.cs b/src/Serilog.Sinks.ColoredConsole/ColoredConsoleLoggerConfigurationExtensions.cs deleted file mode 100644 index a7c599e20..000000000 --- a/src/Serilog.Sinks.ColoredConsole/ColoredConsoleLoggerConfigurationExtensions.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2013-2016 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. - -using System; -using Serilog.Configuration; -using Serilog.Core; -using Serilog.Events; -using Serilog.Sinks.SystemConsole; - -namespace Serilog -{ - public static class ColoredConsoleLoggerConfigurationExtensions - { - const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"; - - /// - /// Writes log events to , using color to differentiate - /// between levels. - /// - /// Logger sink configuration. - /// The minimum level for - /// events passed through the sink. Ignored when is specified. - /// 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} [{Level}] {Message}{NewLine}{Exception}". - /// Supplies culture-specific formatting information, or null. - /// Configuration object allowing method chaining. - public static LoggerConfiguration ColoredConsole( - this LoggerSinkConfiguration sinkConfiguration, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - string outputTemplate = DefaultConsoleOutputTemplate, - IFormatProvider formatProvider = null, - LoggingLevelSwitch levelSwitch = null) - { - if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration)); - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); - return sinkConfiguration.Sink(new ColoredConsoleSink(outputTemplate, formatProvider), restrictedToMinimumLevel, levelSwitch); - } - } -} \ No newline at end of file diff --git a/src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs deleted file mode 100644 index 1237c0e24..000000000 --- a/src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyVersion("2.0.0.0")] - -[assembly: CLSCompliant(true)] - -[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" + - "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + - "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + - "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + - "94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + - "b19485ec")] diff --git a/src/Serilog.Sinks.ColoredConsole/Serilog.Sinks.ColoredConsole.xproj b/src/Serilog.Sinks.ColoredConsole/Serilog.Sinks.ColoredConsole.xproj deleted file mode 100644 index 93f396b17..000000000 --- a/src/Serilog.Sinks.ColoredConsole/Serilog.Sinks.ColoredConsole.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 50b24aca-d8f0-4268-a477-871b0a92a04a - Serilog - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Serilog.Sinks.ColoredConsole/Sinks/ColoredConsole/ColoredConsoleSink.cs b/src/Serilog.Sinks.ColoredConsole/Sinks/ColoredConsole/ColoredConsoleSink.cs deleted file mode 100644 index ebe84f438..000000000 --- a/src/Serilog.Sinks.ColoredConsole/Sinks/ColoredConsole/ColoredConsoleSink.cs +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2013-2016 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. - -using System; -using System.IO; -using Serilog.Core; -using Serilog.Events; -using System.Collections.Generic; -using Serilog.Formatting.Display; -using Serilog.Parsing; - -using IPropertyDictionary = System.Collections.Generic.IReadOnlyDictionary; - -namespace Serilog.Sinks.SystemConsole -{ - class ColoredConsoleSink : ILogEventSink - { - readonly IFormatProvider _formatProvider; - - class Palette - { - public ConsoleColor Base { get; set; } - public ConsoleColor BaseText { get; set; } - public ConsoleColor Highlight { get; set; } - public ConsoleColor HighlightText { get; set; } - } - - static readonly Palette DefaultPalette = new Palette - { - Base = ConsoleColor.Black, - BaseText = ConsoleColor.Gray, - Highlight = ConsoleColor.DarkGray, - HighlightText = ConsoleColor.Gray - }; - - static readonly IDictionary LevelPalettes = new Dictionary - { - { LogEventLevel.Verbose, new Palette { Base = ConsoleColor.Black, BaseText = ConsoleColor.DarkGray, - Highlight = ConsoleColor.Black, HighlightText = ConsoleColor.Gray } }, - { LogEventLevel.Debug, new Palette { Base = ConsoleColor.Black, BaseText = ConsoleColor.Gray, - Highlight = ConsoleColor.Black, HighlightText = ConsoleColor.White } }, - { LogEventLevel.Information, new Palette { Base = ConsoleColor.Black, BaseText = ConsoleColor.White, - Highlight = ConsoleColor.DarkBlue, HighlightText = ConsoleColor.White } }, - { LogEventLevel.Warning, new Palette { Base = ConsoleColor.Black, BaseText = ConsoleColor.Yellow, - Highlight = ConsoleColor.DarkYellow, HighlightText = ConsoleColor.White } }, - { LogEventLevel.Error, new Palette { Base = ConsoleColor.Black, BaseText = ConsoleColor.Red, - Highlight = ConsoleColor.Red, HighlightText = ConsoleColor.White } }, - { LogEventLevel.Fatal, new Palette { Base = ConsoleColor.DarkRed, BaseText = ConsoleColor.White, - Highlight = ConsoleColor.Red, HighlightText = ConsoleColor.White } } - }; - - readonly object _syncRoot = new object(); - readonly MessageTemplate _outputTemplate; - - public ColoredConsoleSink(string outputTemplate, IFormatProvider formatProvider) - { - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); - _outputTemplate = new MessageTemplateParser().Parse(outputTemplate); - _formatProvider = formatProvider; - } - - const string StackFrameLinePrefix = " "; - - public void Emit(LogEvent logEvent) - { - if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); - - var outputProperties = OutputProperties.GetOutputProperties(logEvent); - var palette = GetPalette(logEvent.Level); - var output = Console.Out; - - lock (_syncRoot) - { - try - { - foreach (var outputToken in _outputTemplate.Tokens) - { - var propertyToken = outputToken as PropertyToken; - if (propertyToken == null) - { - RenderOutputToken(palette, outputToken, outputProperties, output); - } - else - { - LogEventPropertyValue propertyValue; - if (!outputProperties.TryGetValue(propertyToken.PropertyName, out propertyValue)) - { - continue; - } - - switch (propertyToken.PropertyName) - { - case OutputProperties.MessagePropertyName: - RenderMessageToken(logEvent, palette, output); - break; - case OutputProperties.ExceptionPropertyName: - RenderExceptionToken(palette, propertyToken, outputProperties, output); - break; - default: - RenderOutputToken(palette, outputToken, outputProperties, output); - break; - } - } - } - } - finally { Console.ResetColor(); } - } - } - - void RenderExceptionToken(Palette palette, MessageTemplateToken outputToken, IPropertyDictionary outputProperties, TextWriter output) - { - var sw = new StringWriter(); - outputToken.Render(outputProperties, sw, _formatProvider); - var lines = new StringReader(sw.ToString()); - string nextLine; - while ((nextLine = lines.ReadLine()) != null) - { - if (nextLine.StartsWith(StackFrameLinePrefix)) - SetBaseColors(palette); - else - SetHighlightColors(palette); - output.WriteLine(nextLine); - } - } - - void RenderMessageToken(LogEvent logEvent, Palette palette, TextWriter output) - { - foreach (var messageToken in logEvent.MessageTemplate.Tokens) - { - var messagePropertyToken = messageToken as PropertyToken; - if (messagePropertyToken != null) - { - SetHighlightColors(palette); - messageToken.Render(logEvent.Properties, output, _formatProvider); - } - else - { - SetBaseColors(palette); - messageToken.Render(logEvent.Properties, output, _formatProvider); - } - } - } - - void RenderOutputToken(Palette palette, MessageTemplateToken outputToken, IPropertyDictionary outputProperties, TextWriter output) - { - SetBaseColors(palette); - outputToken.Render(outputProperties, output, _formatProvider); - } - - static Palette GetPalette(LogEventLevel level) - { - Palette palette; - if (!LevelPalettes.TryGetValue(level, out palette)) - palette = DefaultPalette; - - return palette; - } - - static void SetBaseColors(Palette palette) - { - SetColors(palette.Base, palette.BaseText); - } - - static void SetHighlightColors(Palette palette) - { - SetColors(palette.Highlight, palette.HighlightText); - } - - static void SetColors(ConsoleColor background, ConsoleColor foreground) - { - Console.BackgroundColor = background; - Console.ForegroundColor = foreground; - } - } -} \ No newline at end of file diff --git a/src/Serilog.Sinks.ColoredConsole/project.json b/src/Serilog.Sinks.ColoredConsole/project.json deleted file mode 100644 index 1df5ab3e7..000000000 --- a/src/Serilog.Sinks.ColoredConsole/project.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "2.0.0-beta-*", - "description": "The colored console sink for Serilog", - "authors": [ "Serilog Contributors" ], - "tags": [ "serilog", "console", "coloredconsole" ], - "projectUrl": "http://serilog.net", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", - "iconUrl": "http://serilog.net/images/serilog-sink-nuget.png", - "dependencies": { - "Serilog": { "target": "project" } - }, - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk" - }, - "frameworks": { - "net45": { - }, - "dotnet5.1": { - "dependencies": { - "System.Console": "4.0.0-beta-23516" - } - } - } -} \ No newline at end of file