diff --git a/Serilog.sln b/Serilog.sln index 4af04fe91..42bdab83e 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -35,6 +35,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.SystemConsole EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.PeriodicBatching", "src\Serilog.Sinks.PeriodicBatching\Serilog.Sinks.PeriodicBatching.xproj", "{324C2F52-D9F7-4844-9BC4-9906E228D380}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Observable", "src\Serilog.Sinks.Observable\Serilog.Sinks.Observable.xproj", "{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -73,6 +75,10 @@ Global {324C2F52-D9F7-4844-9BC4-9906E228D380}.Debug|Any CPU.Build.0 = Debug|Any CPU {324C2F52-D9F7-4844-9BC4-9906E228D380}.Release|Any CPU.ActiveCfg = Release|Any CPU {324C2F52-D9F7-4844-9BC4-9906E228D380}.Release|Any CPU.Build.0 = Release|Any CPU + {8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -87,5 +93,6 @@ Global {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} {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} EndGlobalSection EndGlobal diff --git a/src/Serilog.Sinks.Observable/ObservableConfigurationExtensions.cs b/src/Serilog.Sinks.Observable/ObservableConfigurationExtensions.cs new file mode 100644 index 000000000..d48091ff4 --- /dev/null +++ b/src/Serilog.Sinks.Observable/ObservableConfigurationExtensions.cs @@ -0,0 +1,34 @@ +using System; +using Serilog.Configuration; +using Serilog.Core; +using Serilog.Events; +using Serilog.Sinks.Observable; + +namespace Serilog +{ + public static class ObservableConfigurationExtensions + { + /// + /// Write events to Rx observers. + /// + /// Logger sink configuration. + /// An action that provides an observable + /// to which observers can subscribe. + /// 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. + public static LoggerConfiguration Observers( + this LoggerSinkConfiguration sinkConfiguration, + Action> configureObservers, + LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, + LoggingLevelSwitch levelSwitch = null) + { + if (configureObservers == null) throw new ArgumentNullException(nameof(configureObservers)); + var observable = new ObservableSink(); + configureObservers(observable); + return sinkConfiguration.Sink(observable, restrictedToMinimumLevel, levelSwitch); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.Observable/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.Observable/Properties/InternalsVisibleTo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.Observable/Properties/InternalsVisibleTo.cs @@ -0,0 +1,11 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: AssemblyVersion("2.0.0.0")] + +[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" + + "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + + "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + + "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + + "94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + + "b19485ec")] diff --git a/src/Serilog.Sinks.Observable/Serilog.Sinks.Observable.xproj b/src/Serilog.Sinks.Observable/Serilog.Sinks.Observable.xproj new file mode 100644 index 000000000..64b919017 --- /dev/null +++ b/src/Serilog.Sinks.Observable/Serilog.Sinks.Observable.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 8d6c0bb9-d04d-49b6-9043-4a776ad275d5 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog/Sinks/Observable/ObservableSink.cs b/src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs similarity index 100% rename from src/Serilog/Sinks/Observable/ObservableSink.cs rename to src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs diff --git a/src/Serilog.Sinks.Observable/project.json b/src/Serilog.Sinks.Observable/project.json new file mode 100644 index 000000000..d9fbc1040 --- /dev/null +++ b/src/Serilog.Sinks.Observable/project.json @@ -0,0 +1,34 @@ +{ + "version": "2.0.0-beta-*", + "description": "The observable sink for Serilog - Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "observable", "reactive" ], + "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": { + }, + "netcore50": { + "dependencies": { + "System.Collections.Concurrent": "4.0.11-beta-23516" + } + }, + "dotnet5.2": { + "dependencies": { + "System.Collections.Concurrent": "4.0.11-beta-23516" + } + }, + "dotnet5.4": { + "dependencies": { + "System.Collections.Concurrent": "4.0.11-beta-23516" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog/Configuration/LoggerSinkConfiguration.cs b/src/Serilog/Configuration/LoggerSinkConfiguration.cs index feb27b23d..f9ad05c98 100644 --- a/src/Serilog/Configuration/LoggerSinkConfiguration.cs +++ b/src/Serilog/Configuration/LoggerSinkConfiguration.cs @@ -21,7 +21,6 @@ using Serilog.Events; using Serilog.Formatting.Display; using Serilog.Sinks.IOTextWriter; -using Serilog.Sinks.Observable; namespace Serilog.Configuration { @@ -177,27 +176,6 @@ public LoggerConfiguration Logger( { if (logger == null) throw new ArgumentNullException(nameof(logger)); return Sink(new SecondaryLoggerSink(logger, attemptDispose: false), restrictedToMinimumLevel); - } - - /// - /// Write events to Rx observers. - /// - /// An action that provides an observable - /// to which observers can subscribe. - /// 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. - public LoggerConfiguration Observers( - Action> configureObservers, - LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, - LoggingLevelSwitch levelSwitch = null) - { - if (configureObservers == null) throw new ArgumentNullException(nameof(configureObservers)); - var observable = new ObservableSink(); - configureObservers(observable); - return Sink(observable, restrictedToMinimumLevel, levelSwitch); - } + } } } diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 1dfa53bc3..0c93473d1 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -15,7 +15,8 @@ "Serilog.Sinks.DiagnosticTrace": { "target": "project" }, "Serilog.Sinks.IOFile": { "target": "project" }, "Serilog.Sinks.RollingFile": { "target": "project" }, - "Serilog.Sinks.PeriodicBatching": {"target": "project"} + "Serilog.Sinks.PeriodicBatching": { "target": "project" }, + "Serilog.Sinks.Observable": {"target": "project"} }, "frameworks": { "dnx451": {