From e0093bc3e9264cf7ae61afc295f9fa0ed7a2a798 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Tue, 12 Jan 2016 15:02:13 +1000 Subject: [PATCH] Initial cut of console sink as an example of porting sinks --- Serilog.sln | 10 ++++ .../ConsoleSink.cs | 2 +- .../LoggingExtentsions.cs | 39 ++++++++++++ .../Serilog.Sinks.Console.xproj | 20 +++++++ src/Serilog.Sinks.Console/project.json | 60 +++++++++++++++++++ .../LoggerConfigurationFullNetFxExtensions.cs | 26 +------- test/Serilog.Tests/project.json | 5 +- 7 files changed, 134 insertions(+), 28 deletions(-) rename src/{Serilog/Sinks/SystemConsole => Serilog.Sinks.Console}/ConsoleSink.cs (96%) create mode 100644 src/Serilog.Sinks.Console/LoggingExtentsions.cs create mode 100644 src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj create mode 100644 src/Serilog.Sinks.Console/project.json diff --git a/Serilog.sln b/Serilog.sln index 180f4d01c..c66aa8182 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -21,6 +21,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog", "src\Serilog\Seri EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Tests", "test\Serilog.Tests\Serilog.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console", "src\Serilog.Sinks.Console\Serilog.Sinks.Console.xproj", "{866A028E-27DB-49A0-AC78-E5FEF247C099}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{9EC69873-5A97-4C25-AB5A-31DDE589B2D9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +39,10 @@ Global {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU + {866A028E-27DB-49A0-AC78-E5FEF247C099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {866A028E-27DB-49A0-AC78-E5FEF247C099}.Debug|Any CPU.Build.0 = Debug|Any CPU + {866A028E-27DB-49A0-AC78-E5FEF247C099}.Release|Any CPU.ActiveCfg = Release|Any CPU + {866A028E-27DB-49A0-AC78-E5FEF247C099}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -42,5 +50,7 @@ Global GlobalSection(NestedProjects) = preSolution {803CD13A-D54B-4CEC-A55F-E22AE3D93B3C} = {037440DE-440B-4129-9F7A-09B42D00397E} {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {0D135C0C-A60B-454A-A2F4-CD74A30E04B0} + {866A028E-27DB-49A0-AC78-E5FEF247C099} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} + {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} = {037440DE-440B-4129-9F7A-09B42D00397E} EndGlobalSection EndGlobal diff --git a/src/Serilog/Sinks/SystemConsole/ConsoleSink.cs b/src/Serilog.Sinks.Console/ConsoleSink.cs similarity index 96% rename from src/Serilog/Sinks/SystemConsole/ConsoleSink.cs rename to src/Serilog.Sinks.Console/ConsoleSink.cs index eca5e745a..e7af874e3 100644 --- a/src/Serilog/Sinks/SystemConsole/ConsoleSink.cs +++ b/src/Serilog.Sinks.Console/ConsoleSink.cs @@ -20,7 +20,7 @@ namespace Serilog.Sinks.SystemConsole { - class ConsoleSink : ILogEventSink + public class ConsoleSink : ILogEventSink { readonly ITextFormatter _textFormatter; diff --git a/src/Serilog.Sinks.Console/LoggingExtentsions.cs b/src/Serilog.Sinks.Console/LoggingExtentsions.cs new file mode 100644 index 000000000..2bf0f55cb --- /dev/null +++ b/src/Serilog.Sinks.Console/LoggingExtentsions.cs @@ -0,0 +1,39 @@ +using System; +using Serilog.Configuration; +using Serilog.Core; +using Serilog.Events; +using Serilog.Formatting.Display; + + +namespace Serilog.Sinks.SystemConsole +{ + public static class LoggingExtentsions + { + const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"; + + /// + /// Writes log events to . + /// + /// 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 Console( + 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)); + var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); + return sinkConfiguration.Sink(new ConsoleSink(formatter), restrictedToMinimumLevel, levelSwitch); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj new file mode 100644 index 000000000..0e7e4c6c4 --- /dev/null +++ b/src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 866a028e-27db-49a0-ac78-e5fef247c099 + Serilog.Sinks.Console + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Serilog.Sinks.Console/project.json b/src/Serilog.Sinks.Console/project.json new file mode 100644 index 000000000..7aa7dd867 --- /dev/null +++ b/src/Serilog.Sinks.Console/project.json @@ -0,0 +1,60 @@ +{ + "version": "2.0.0-beta-*", + "description": "The console sink for Seriolog - Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "logging", "semantic", "structured", "console" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-nuget.png", + "frameworks": { + "net40": { + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworkAssemblies": { + "System.Configuration": "" + }, + "dependencies": { + "Microsoft.Bcl.Async": "1.0.168", + "Serilog": "2.0.0-beta-*" + } + }, + "net45": { + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworkAssemblies": { + "System.Configuration": "" + }, + "dependencies": { + "Serilog": "2.0.0-beta-*" + } + }, + "dnx451": { + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworkAssemblies": { + "System.Configuration": "" + }, + "dependencies": { + "Serilog": "2.0.0-beta-*" + } + }, + "dotnet5.4": { + "dependencies": { + "Microsoft.CSharp": "4.0.1-beta-23516", + "Serilog": "2.0.0-beta-*", + "System.Collections.Concurrent": "4.0.11-beta-23516", + "System.Console": "4.0.0-beta-23516", + "System.Diagnostics.Process": "4.1.0-beta-23516", + "System.Diagnostics.TraceSource": "4.0.0-beta-23516", + "System.IO": "4.0.11-beta-23516", + "System.IO.FileSystem": "4.0.1-beta-23516", + "System.Linq": "4.0.1-beta-23516", + "System.Text.RegularExpressions": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516" + } + } + } +} diff --git a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs index 0a216eb53..4695e4122 100644 --- a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs +++ b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs @@ -50,30 +50,6 @@ public static class LoggerConfigurationFullNetFxExtensions const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024; const int DefaultRetainedFileCountLimit = 31; // A long month of logs - /// - /// Writes log events to . - /// - /// 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 Console( - 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)); - var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); - return sinkConfiguration.Sink(new ConsoleSink(formatter), restrictedToMinimumLevel, levelSwitch); - } /// /// Writes log events to , using color to differentiate @@ -322,7 +298,7 @@ public static LoggerConfiguration AppSettings( { if (settingPrefix.Contains(":")) throw new ArgumentException("Custom setting prefixes cannot contain the colon (:) character."); if (settingPrefix == "serilog") throw new ArgumentException("The value \"serilog\" is not a permitted setting prefix. To use the default, do not specify a custom prefix at all."); - if (string.IsNullOrWhiteSpace(settingPrefix)) throw new ArgumentException("To use the default setting prefix, do not supply the settingPrefix parameter, instead pass the default null."); + if (String.IsNullOrWhiteSpace(settingPrefix)) throw new ArgumentException("To use the default setting prefix, do not supply the settingPrefix parameter, instead pass the default null."); } return settingConfiguration.Settings(new AppSettingsSettings(settingPrefix)); diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index e3ec70b7e..129d827c6 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -1,4 +1,4 @@ -{ +{ "version": "2.0.0-beta-*", "commands": { "test": "xunit.runner.dnx", @@ -10,7 +10,8 @@ "Serilog": { "target": "project" }, "xunit": "2.1.0", "xunit.runner.visualstudio": "2.1.0", - "xunit.runner.dnx": "2.1.0-rc1-build204" + "xunit.runner.dnx": "2.1.0-rc1-build204", + "Serilog.Sinks.Console": "2.0.0-beta-*" }, "frameworks": { "dnx451": {