From 413d81bde1ba2278d21e5b24d352270ba8974de6 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 16 Jan 2016 13:55:14 +1000 Subject: [PATCH] Moved Serilog.Sinks.DiagnosticTrace to new project --- Serilog.sln | 7 +++ .../DiagnosticTraceConfigurationExtensions.cs | 52 +++++++++++++++++++ .../Serilog.Sinks.DiagnosticTrace.xproj | 18 +++++++ .../DiagnosticTrace/DiagnosticTraceSink.cs | 0 .../project.json | 24 +++++++++ .../LoggerConfigurationFullNetFxExtensions.cs | 31 ++--------- .../Settings/KeyValuePairSettingsTests.cs | 3 +- test/Serilog.Tests/project.json | 3 +- 8 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 src/Serilog.Sinks.DiagnosticTrace/DiagnosticTraceConfigurationExtensions.cs create mode 100644 src/Serilog.Sinks.DiagnosticTrace/Serilog.Sinks.DiagnosticTrace.xproj rename src/{Serilog => Serilog.Sinks.DiagnosticTrace}/Sinks/DiagnosticTrace/DiagnosticTraceSink.cs (100%) create mode 100644 src/Serilog.Sinks.DiagnosticTrace/project.json diff --git a/Serilog.sln b/Serilog.sln index c66aa8182..233f2154e 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -25,6 +25,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console", "sr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{9EC69873-5A97-4C25-AB5A-31DDE589B2D9}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.DiagnosticTrace", "src\Serilog.Sinks.DiagnosticTrace\Serilog.Sinks.DiagnosticTrace.xproj", "{8849C92D-2120-4C82-8226-22DF40195237}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,6 +45,10 @@ Global {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 + {8849C92D-2120-4C82-8226-22DF40195237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8849C92D-2120-4C82-8226-22DF40195237}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -52,5 +58,6 @@ Global {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} + {8849C92D-2120-4C82-8226-22DF40195237} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} EndGlobalSection EndGlobal diff --git a/src/Serilog.Sinks.DiagnosticTrace/DiagnosticTraceConfigurationExtensions.cs b/src/Serilog.Sinks.DiagnosticTrace/DiagnosticTraceConfigurationExtensions.cs new file mode 100644 index 000000000..22c07ee35 --- /dev/null +++ b/src/Serilog.Sinks.DiagnosticTrace/DiagnosticTraceConfigurationExtensions.cs @@ -0,0 +1,52 @@ +// 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.Formatting.Display; +using Serilog.Sinks.DiagnosticTrace; + +namespace Serilog +{ + public static class DiagnosticTraceConfigurationExtensions + { + /// + /// Write log events to the . + /// + /// 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 Trace( + this LoggerSinkConfiguration sinkConfiguration, + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, + string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate, + 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 DiagnosticTraceSink(formatter), restrictedToMinimumLevel, levelSwitch); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.DiagnosticTrace/Serilog.Sinks.DiagnosticTrace.xproj b/src/Serilog.Sinks.DiagnosticTrace/Serilog.Sinks.DiagnosticTrace.xproj new file mode 100644 index 000000000..cc8261c1e --- /dev/null +++ b/src/Serilog.Sinks.DiagnosticTrace/Serilog.Sinks.DiagnosticTrace.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 8849c92d-2120-4c82-8226-22df40195237 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog/Sinks/DiagnosticTrace/DiagnosticTraceSink.cs b/src/Serilog.Sinks.DiagnosticTrace/Sinks/DiagnosticTrace/DiagnosticTraceSink.cs similarity index 100% rename from src/Serilog/Sinks/DiagnosticTrace/DiagnosticTraceSink.cs rename to src/Serilog.Sinks.DiagnosticTrace/Sinks/DiagnosticTrace/DiagnosticTraceSink.cs diff --git a/src/Serilog.Sinks.DiagnosticTrace/project.json b/src/Serilog.Sinks.DiagnosticTrace/project.json new file mode 100644 index 000000000..e1002d069 --- /dev/null +++ b/src/Serilog.Sinks.DiagnosticTrace/project.json @@ -0,0 +1,24 @@ +{ + "version": "2.0.0-beta-*", + "description": "The console sink for Serilog - Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "console" ], + "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.Diagnostics.TraceSource": "4.0.0-beta-23516" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs index d2ea26b96..13426406e 100644 --- a/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs +++ b/src/Serilog/LoggerConfigurationFullNetFxExtensions.cs @@ -21,7 +21,6 @@ using Serilog.Events; using Serilog.Formatting.Display; using Serilog.Formatting.Raw; -using Serilog.Sinks.DiagnosticTrace; using Serilog.Sinks.SystemConsole; #if PROCESS @@ -45,7 +44,8 @@ namespace Serilog /// public static class LoggerConfigurationFullNetFxExtensions { - const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"; + //TODO: Need to confirm this is the best location for this default. Used in File, Trace, RollingFike + public const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"; const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"; const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024; const int DefaultRetainedFileCountLimit = 31; // A long month of logs @@ -182,32 +182,7 @@ public static LoggerConfiguration RollingFile( return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch); } #endif - - /// - /// Write log events to the . - /// - /// 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 Trace( - this LoggerSinkConfiguration sinkConfiguration, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - string outputTemplate = DefaultOutputTemplate, - 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 DiagnosticTraceSink(formatter), restrictedToMinimumLevel, levelSwitch); - } - + #if LOGCONTEXT /// /// Enrich log events with properties from . diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index 26059b6b3..9a6a5d9a4 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -71,13 +71,12 @@ public void FindsConfigurationMethodsWithinAnAssembly() .Distinct() .ToList(); - Assert.Equal(5, configurationMethods.Count); + Assert.Equal(4, configurationMethods.Count); Assert.True(configurationMethods.Contains("ColoredConsole")); Assert.True(configurationMethods.Contains("DumpFile")); Assert.True(configurationMethods.Contains("File")); Assert.True(configurationMethods.Contains("RollingFile")); - Assert.True(configurationMethods.Contains("Trace")); } [Fact] diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 0aa01e790..06c5beb3f 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -11,7 +11,8 @@ "xunit": "2.1.0", "xunit.runner.visualstudio": "2.1.0", "xunit.runner.dnx": "2.1.0-rc1-build204", - "Serilog.Sinks.Console": { "target": "project" } + "Serilog.Sinks.Console": { "target": "project" }, + "Serilog.Sinks.DiagnosticTrace": { "target": "project" } }, "frameworks": { "dnx451": {