diff --git a/Serilog.sln b/Serilog.sln index 42bdab83e..c493ad2b8 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.PeriodicBatch EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Observable", "src\Serilog.Sinks.Observable\Serilog.Sinks.Observable.xproj", "{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.IOTextWriter", "src\Serilog.Sinks.IOTextWriter\Serilog.Sinks.IOTextWriter.xproj", "{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +81,10 @@ Global {8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Debug|Any CPU.Build.0 = Debug|Any CPU {8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Release|Any CPU.ActiveCfg = Release|Any CPU {8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Release|Any CPU.Build.0 = Release|Any CPU + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -94,5 +100,6 @@ Global {50B24ACA-D8F0-4268-A477-871B0A92A04A} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} {324C2F52-D9F7-4844-9BC4-9906E228D380} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} {8D6C0BB9-D04D-49B6-9043-4A776AD275D5} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} EndGlobalSection EndGlobal diff --git a/src/Serilog.Sinks.IOTextWriter/IOTextWriterConfigurationExtensions.cs b/src/Serilog.Sinks.IOTextWriter/IOTextWriterConfigurationExtensions.cs new file mode 100644 index 000000000..5247b015a --- /dev/null +++ b/src/Serilog.Sinks.IOTextWriter/IOTextWriterConfigurationExtensions.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using Serilog.Configuration; +using Serilog.Core; +using Serilog.Events; +using Serilog.Formatting.Display; +using Serilog.Sinks.IOTextWriter; + +namespace Serilog +{ + public static class IOTextWriterConfigurationExtensions + { + /// + /// Write log events to the provided . + /// + /// Logger sink configuration. + /// The text writer to write log events to. + /// Message template describing the output format. + /// 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. + /// Configuration object allowing method chaining. + /// Supplies culture-specific formatting information, or null. + /// + public static LoggerConfiguration TextWriter( + this LoggerSinkConfiguration sinkConfiguration, + TextWriter textWriter, + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, + string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate, + IFormatProvider formatProvider = null, + LoggingLevelSwitch levelSwitch = null) + { + if (textWriter == null) throw new ArgumentNullException(nameof(textWriter)); + if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); + + var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); + var sink = new TextWriterSink(textWriter, formatter); + return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.IOTextWriter/Serilog.Sinks.IOTextWriter.xproj b/src/Serilog.Sinks.IOTextWriter/Serilog.Sinks.IOTextWriter.xproj new file mode 100644 index 000000000..26ffe2039 --- /dev/null +++ b/src/Serilog.Sinks.IOTextWriter/Serilog.Sinks.IOTextWriter.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + e85abec7-9b4c-432c-9a04-ac5be9205d9f + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog/Sinks/IOTextWriter/TextWriterSink.cs b/src/Serilog.Sinks.IOTextWriter/Sinks/IOTextWriter/TextWriterSink.cs similarity index 100% rename from src/Serilog/Sinks/IOTextWriter/TextWriterSink.cs rename to src/Serilog.Sinks.IOTextWriter/Sinks/IOTextWriter/TextWriterSink.cs diff --git a/src/Serilog.Sinks.IOTextWriter/project.json b/src/Serilog.Sinks.IOTextWriter/project.json new file mode 100644 index 000000000..dce7d016f --- /dev/null +++ b/src/Serilog.Sinks.IOTextWriter/project.json @@ -0,0 +1,29 @@ +{ + "version": "2.0.0-beta-*", + "description": "The IO Text Writer sink for Serilog - Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "IO", "text", "writer"], + "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.IO": "4.0.11-beta-23516" + } + }, + "dotnet5.4": { + "dependencies": { + "System.IO": "4.0.11-beta-23516" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.xproj b/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.xproj index 0b37f33e2..0bd6dfd90 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.xproj +++ b/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.xproj @@ -4,17 +4,15 @@ 14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - 324c2f52-d9f7-4844-9bc4-9906e228d380 - Serilog.Sinks.PeriodicBatching + Serilog ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ - 2.0 - + \ No newline at end of file diff --git a/src/Serilog/Configuration/LoggerSinkConfiguration.cs b/src/Serilog/Configuration/LoggerSinkConfiguration.cs index f9ad05c98..eabed4dfc 100644 --- a/src/Serilog/Configuration/LoggerSinkConfiguration.cs +++ b/src/Serilog/Configuration/LoggerSinkConfiguration.cs @@ -19,8 +19,7 @@ using Serilog.Core.Sinks; using Serilog.Debugging; using Serilog.Events; -using Serilog.Formatting.Display; -using Serilog.Sinks.IOTextWriter; +using Serilog.Formatting.Display; namespace Serilog.Configuration { @@ -109,32 +108,7 @@ public LoggerConfiguration Sink( return Sink(new TSink(), restrictedToMinimumLevel, levelSwitch); } - /// - /// Write log events to the provided . - /// - /// The text writer to write log events to. - /// Message template describing the output format. - /// 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. - /// Configuration object allowing method chaining. - /// Supplies culture-specific formatting information, or null. - /// - public LoggerConfiguration TextWriter( - TextWriter textWriter, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - string outputTemplate = DefaultOutputTemplate, - IFormatProvider formatProvider = null, - LoggingLevelSwitch levelSwitch = null) - { - if (textWriter == null) throw new ArgumentNullException(nameof(textWriter)); - if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); - var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); - var sink = new TextWriterSink(textWriter, formatter); - return Sink(sink, restrictedToMinimumLevel, levelSwitch); - } /// /// Write log events to a sub-logger, where further processing may occur. Events through diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 0c93473d1..8b62dbacb 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -16,7 +16,8 @@ "Serilog.Sinks.IOFile": { "target": "project" }, "Serilog.Sinks.RollingFile": { "target": "project" }, "Serilog.Sinks.PeriodicBatching": { "target": "project" }, - "Serilog.Sinks.Observable": {"target": "project"} + "Serilog.Sinks.Observable": { "target": "project" }, + "Serilog.Sinks.IOTextWriter": {"target": "project"} }, "frameworks": { "dnx451": {