From 5cf24776637a9df99c4f728ff9f71341805911ae Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Wed, 20 Jan 2016 13:45:31 +1000 Subject: [PATCH] Removed redundant files --- Serilog.sln | 7 + .../LoggerConfigurationFullNetFxExtensions.cs | 3 +- .../Sinks/SystemConsole/ColoredConsoleSink.cs | 176 ------------------ 3 files changed, 8 insertions(+), 178 deletions(-) delete mode 100644 src/Serilog/Sinks/SystemConsole/ColoredConsoleSink.cs diff --git a/Serilog.sln b/Serilog.sln index 95743ebb0..5fc811ffb 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -31,6 +31,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.IOFile", "src EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.RollingFile", "src\Serilog.Sinks.RollingFile\Serilog.Sinks.RollingFile.xproj", "{A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.SystemConsole", "src\Serilog.Sinks.SystemConsole\Serilog.Sinks.SystemConsole.xproj", "{50B24ACA-D8F0-4268-A477-871B0A92A04A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Debug|Any CPU.Build.0 = Debug|Any CPU {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21}.Release|Any CPU.Build.0 = Release|Any CPU + {50B24ACA-D8F0-4268-A477-871B0A92A04A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50B24ACA-D8F0-4268-A477-871B0A92A04A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50B24ACA-D8F0-4268-A477-871B0A92A04A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50B24ACA-D8F0-4268-A477-871B0A92A04A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -73,5 +79,6 @@ Global {8849C92D-2120-4C82-8226-22DF40195237} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} {57E0ED0E-0F45-48AB-A73D-6A92B7C32095} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} + {50B24ACA-D8F0-4268-A477-871B0A92A04A} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} EndGlobalSection EndGlobal diff --git a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs index 0a521a095..d322d3ddb 100644 --- a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs +++ b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs @@ -20,8 +20,7 @@ using Serilog.Enrichers; using Serilog.Events; using Serilog.Formatting.Display; -using Serilog.Formatting.Raw; -using Serilog.Sinks.SystemConsole; +using Serilog.Formatting.Raw; #if PROCESS using System.Diagnostics; diff --git a/src/Serilog/Sinks/SystemConsole/ColoredConsoleSink.cs b/src/Serilog/Sinks/SystemConsole/ColoredConsoleSink.cs deleted file mode 100644 index 43d64d397..000000000 --- a/src/Serilog/Sinks/SystemConsole/ColoredConsoleSink.cs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2013-2015 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; - -#if NET40 -using IPropertyDictionary = System.Collections.Generic.IDictionary; -#else -using IPropertyDictionary = System.Collections.Generic.IReadOnlyDictionary; -#endif - -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 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; - } - } -}