diff --git a/Serilog.sln b/Serilog.sln index e86050cf4..07fed6825 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -23,8 +23,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Tests", "test\Seril 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 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.PeriodicBatching", "src\Serilog.Sinks.PeriodicBatching\Serilog.Sinks.PeriodicBatching.xproj", "{324C2F52-D9F7-4844-9BC4-9906E228D380}" @@ -39,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.TextWriter", EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Trace", "src\Serilog.Sinks.Trace\Serilog.Sinks.Trace.xproj", "{8849C92D-2120-4C82-8226-22DF40195237}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Settings.AppSettings", "src\Serilog.Settings.AppSettings\Serilog.Settings.AppSettings.xproj", "{0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -85,6 +85,10 @@ Global {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 + {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -92,14 +96,14 @@ 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} - {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21} = {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} - {50B24ACA-D8F0-4268-A477-871B0A92A04A} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} - {57E0ED0E-0F45-48AB-A73D-6A92B7C32095} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} - {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} - {8849C92D-2120-4C82-8226-22DF40195237} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9} + {866A028E-27DB-49A0-AC78-E5FEF247C099} = {037440DE-440B-4129-9F7A-09B42D00397E} + {A3E6E5B4-995F-4C3D-9673-A4B6000F4E21} = {037440DE-440B-4129-9F7A-09B42D00397E} + {324C2F52-D9F7-4844-9BC4-9906E228D380} = {037440DE-440B-4129-9F7A-09B42D00397E} + {8D6C0BB9-D04D-49B6-9043-4A776AD275D5} = {037440DE-440B-4129-9F7A-09B42D00397E} + {50B24ACA-D8F0-4268-A477-871B0A92A04A} = {037440DE-440B-4129-9F7A-09B42D00397E} + {57E0ED0E-0F45-48AB-A73D-6A92B7C32095} = {037440DE-440B-4129-9F7A-09B42D00397E} + {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {037440DE-440B-4129-9F7A-09B42D00397E} + {8849C92D-2120-4C82-8226-22DF40195237} = {037440DE-440B-4129-9F7A-09B42D00397E} + {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4} = {037440DE-440B-4129-9F7A-09B42D00397E} EndGlobalSection EndGlobal diff --git a/src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs b/src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs new file mode 100644 index 000000000..28018e9ae --- /dev/null +++ b/src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs @@ -0,0 +1,53 @@ +// 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.Settings.AppSettings; + +namespace Serilog +{ + /// + /// Extends with support for System.Configuration appSettings elements. + /// + public static class AppSettingsLoggerConfigurationExtensions + { + /// + /// Reads the <appSettings> element of App.config or Web.config, searching for for keys + /// that look like: serilog:*, which are used to configure + /// the logger. To add a sink, use a key like serilog:write-to:File.path for + /// each parameter to the sink's configuration method. To add an additional assembly + /// containing sinks, use serilog:using. To set the level use + /// serilog:minimum-level. + /// + /// Logger setting configuration. + /// Prefix to use when reading keys in appSettings. If specified the value + /// will be prepended to the setting keys and followed by :, for example "myapp" will use "myapp:serilog:minumum-level. If null + /// no prefix is applied. + /// An object allowing configuration to continue. + public static LoggerConfiguration AppSettings( + this LoggerSettingsConfiguration settingConfiguration, string settingPrefix = null) + { + if (settingConfiguration == null) throw new ArgumentNullException(nameof(settingConfiguration)); + if (settingPrefix != null) + { + 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."); + } + + return settingConfiguration.Settings(new AppSettingsSettings(settingPrefix)); + } + } +} diff --git a/src/Serilog.Sinks.File/Properties/InternalsVisibleTo.cs b/src/Serilog.Settings.AppSettings/Properties/AssemblyInfo.cs similarity index 100% rename from src/Serilog.Sinks.File/Properties/InternalsVisibleTo.cs rename to src/Serilog.Settings.AppSettings/Properties/AssemblyInfo.cs diff --git a/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj b/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj new file mode 100644 index 000000000..1e99e05da --- /dev/null +++ b/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 0d9f37e3-2cb4-4c0d-a307-32bb71defdd4 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + True + + + \ No newline at end of file diff --git a/src/Serilog/Settings/AppSettings/AppSettingsSettings.cs b/src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs similarity index 90% rename from src/Serilog/Settings/AppSettings/AppSettingsSettings.cs rename to src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs index a21bb6c6d..6850141a3 100644 --- a/src/Serilog/Settings/AppSettings/AppSettingsSettings.cs +++ b/src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if APPSETTINGS using System; using System.Configuration; using System.Linq; @@ -40,9 +39,7 @@ public void Configure(LoggerConfiguration loggerConfiguration) .Where(k => k.StartsWith(_settingPrefix)) .ToDictionary(k => k.Substring(_settingPrefix.Length), k => Environment.ExpandEnvironmentVariables(settings[k])); - var keyValuePairSettings = new KeyValuePairSettings(pairs); - keyValuePairSettings.Configure(loggerConfiguration); + loggerConfiguration.ReadFrom.KeyValuePairs(pairs); } } } -#endif diff --git a/src/Serilog.Settings.AppSettings/project.json b/src/Serilog.Settings.AppSettings/project.json new file mode 100644 index 000000000..80c0bb062 --- /dev/null +++ b/src/Serilog.Settings.AppSettings/project.json @@ -0,0 +1,22 @@ +{ + "version": "2.0.0-beta-*", + "description": "XML configuration (System.Configuration ) support for Serilog.", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "xml" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-configuration-nuget.png", + "dependencies": { + "Serilog": { "target": "project" } + }, + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworks": { + "net45": { + "frameworkAssemblies": { + "System.Configuration": "" + } + } + } +} diff --git a/src/Serilog.Sinks.Observable/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs similarity index 100% rename from src/Serilog.Sinks.Observable/Properties/InternalsVisibleTo.cs rename to src/Serilog.Sinks.ColoredConsole/Properties/AssemblyInfo.cs diff --git a/src/Serilog.Sinks.PeriodicBatching/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs similarity index 100% rename from src/Serilog.Sinks.PeriodicBatching/Properties/InternalsVisibleTo.cs rename to src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs diff --git a/src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.File/Properties/AssemblyInfo.cs similarity index 100% rename from src/Serilog.Sinks.RollingFile/Properties/InternalsVisibleTo.cs rename to src/Serilog.Sinks.File/Properties/AssemblyInfo.cs diff --git a/src/Serilog/Properties/InternalsVisibleTo.cs b/src/Serilog.Sinks.Observable/Properties/AssemblyInfo.cs similarity index 100% rename from src/Serilog/Properties/InternalsVisibleTo.cs rename to src/Serilog.Sinks.Observable/Properties/AssemblyInfo.cs diff --git a/src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs b/src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs index fcec3848f..c5c874aa5 100644 --- a/src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs +++ b/src/Serilog.Sinks.Observable/Sinks/Observable/ObservableSink.cs @@ -94,11 +94,7 @@ public void Emit(LogEvent logEvent) { if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); -#if NET40 - Thread.MemoryBarrier(); -#else Interlocked.MemoryBarrier(); -#endif IList exceptions = null; diff --git a/src/Serilog.Sinks.PeriodicBatching/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.PeriodicBatching/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.PeriodicBatching/Properties/AssemblyInfo.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.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs index b88053052..13566246e 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs @@ -42,10 +42,10 @@ public abstract class PeriodicBatchingSink : ILogEventSink, IDisposable readonly Queue _waitingBatch = new Queue(); readonly object _stateLock = new object(); -#if NO_TIMER - readonly PortableTimer _timer; -#else +#if WAITABLE_TIMER readonly Timer _timer; +#else + readonly PortableTimer _timer; #endif bool _unloading; bool _started; @@ -61,20 +61,20 @@ protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period) _queue = new ConcurrentQueue(); _status = new BatchedConnectionStatus(period); -#if NO_TIMER - _timer = new PortableTimer(cancel => OnTick()); -#else +#if WAITABLE_TIMER _timer = new Timer(s => OnTick(), null, -1, -1); +#else + _timer = new PortableTimer(cancel => OnTick()); #endif -#if !NO_APPDOMAIN +#if APPDOMAIN AppDomain.CurrentDomain.DomainUnload += OnAppDomainUnloading; AppDomain.CurrentDomain.ProcessExit += OnAppDomainUnloading; AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnloading; #endif } -#if !NO_APPDOMAIN +#if APPDOMAIN void OnAppDomainUnloading(object sender, EventArgs args) { var eventArgs = args as UnhandledExceptionEventArgs; @@ -95,18 +95,18 @@ void CloseAndFlush() _unloading = true; } -#if !NO_APPDOMAIN +#if APPDOMAIN AppDomain.CurrentDomain.DomainUnload -= OnAppDomainUnloading; AppDomain.CurrentDomain.ProcessExit -= OnAppDomainUnloading; AppDomain.CurrentDomain.UnhandledException -= OnAppDomainUnloading; #endif -#if NO_TIMER - _timer.Dispose(); -#else +#if WAITABLE_TIMER var wh = new ManualResetEvent(false); if (_timer.Dispose(wh)) wh.WaitOne(); +#else + _timer.Dispose(); #endif OnTick(); @@ -221,16 +221,12 @@ void OnTick() void SetTimer(TimeSpan interval) { -#if NO_TIMER - _timer.Start(interval); +#if WAITABLE_TIMER + _timer.Change(interval, Timeout.InfiniteTimeSpan); #else - _timer.Change(interval, -#if NET40 - TimeSpan.FromMilliseconds(-1)); -#else - Timeout.InfiniteTimeSpan); -#endif + _timer.Start(interval); #endif + } /// diff --git a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs index b22a2afa8..f381fbf36 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if NO_TIMER +#if !WAITABLE_TIMER using Serilog.Debugging; using System; diff --git a/src/Serilog.Sinks.PeriodicBatching/project.json b/src/Serilog.Sinks.PeriodicBatching/project.json index bb06fe09a..f748db1a5 100644 --- a/src/Serilog.Sinks.PeriodicBatching/project.json +++ b/src/Serilog.Sinks.PeriodicBatching/project.json @@ -2,29 +2,26 @@ "version": "2.0.0-beta-*", "description": "The periodic batching sink for Serilog", "authors": [ "Serilog Contributors" ], - "tags": [ "serilog", "batching", "timer"], + "tags": [ "serilog", "batching", "timer" ], "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" }, + "Serilog": { "target": "project" }, }, "compilationOptions": { "keyFile": "../../assets/Serilog.snk" }, "frameworks": { "net45": { - "frameworkAssemblies": { - "System.Configuration": "" + "compilationOptions": { + "define": [ "APPDOMAIN", "WAITABLE_TIMER" ] } }, "dotnet5.2": { - "compilationOptions": { - "define": [ "NO_TIMER", "NO_APPDOMAIN" ] - }, "dependencies": { "System.Collections.Concurrent": "4.0.11-beta-23516" } } } -} \ No newline at end of file +} diff --git a/src/Serilog.Sinks.RollingFile/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.RollingFile/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.RollingFile/Properties/AssemblyInfo.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.TextWriter/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.TextWriter/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.TextWriter/Properties/AssemblyInfo.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.Trace/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.Trace/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog.Sinks.Trace/Properties/AssemblyInfo.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/LoggerConfigurationExtensions.cs b/src/Serilog/LoggerConfigurationExtensions.cs index 18cfc728d..229f71cdd 100644 --- a/src/Serilog/LoggerConfigurationExtensions.cs +++ b/src/Serilog/LoggerConfigurationExtensions.cs @@ -26,11 +26,6 @@ using System.Diagnostics; #endif - -#if APPSETTINGS -using Serilog.Settings.AppSettings; -#endif - namespace Serilog { /// @@ -91,34 +86,5 @@ public static LoggerConfiguration WithEnvironmentUserName( return enrichmentConfiguration.With(); } #endif - -#if APPSETTINGS - /// - /// Reads the <appSettings> element of App.config or Web.config, searching for for keys - /// that look like: serilog:*, which are used to configure - /// the logger. To add a sink, use a key like serilog:write-to:File.path for - /// each parameter to the sink's configuration method. To add an additional assembly - /// containing sinks, use serilog:using. To set the level use - /// serilog:minimum-level. - /// - /// Logger setting configuration. - /// Prefix to use when reading keys in appSettings. If specified the value - /// will be prepended to the setting keys and followed by :, for example "myapp" will use "myapp:serilog:minumum-level. If null - /// no prefix is applied. - /// An object allowing configuration to continue. - public static LoggerConfiguration AppSettings( - this LoggerSettingsConfiguration settingConfiguration, string settingPrefix = null) - { - if (settingConfiguration == null) throw new ArgumentNullException(nameof(settingConfiguration)); - if (settingPrefix != null) - { - 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."); - } - - return settingConfiguration.Settings(new AppSettingsSettings(settingPrefix)); - } -#endif } } diff --git a/src/Serilog/Parsing/MessageTemplateToken.cs b/src/Serilog/Parsing/MessageTemplateToken.cs index dccd53519..52a3abcb2 100644 --- a/src/Serilog/Parsing/MessageTemplateToken.cs +++ b/src/Serilog/Parsing/MessageTemplateToken.cs @@ -13,13 +13,9 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.IO; - -#if NET40 -using IPropertyDictionary = System.Collections.Generic.IDictionary; -#else -using IPropertyDictionary = System.Collections.Generic.IReadOnlyDictionary; -#endif +using Serilog.Events; namespace Serilog.Parsing { @@ -40,6 +36,7 @@ protected MessageTemplateToken(int startIndex) /// /// The token's start index in the template. /// + // ReSharper disable once UnusedAutoPropertyAccessor.Global public int StartIndex { get; } /// @@ -53,6 +50,6 @@ protected MessageTemplateToken(int startIndex) /// Properties that may be represented by the token. /// Output for the rendered string. /// Supplies culture-specific formatting information, or null. - public abstract void Render(IPropertyDictionary properties, TextWriter output, IFormatProvider formatProvider = null); + public abstract void Render(IReadOnlyDictionary properties, TextWriter output, IFormatProvider formatProvider = null); } } \ No newline at end of file diff --git a/src/Serilog/Parsing/PropertyToken.cs b/src/Serilog/Parsing/PropertyToken.cs index f7551a283..45892184e 100644 --- a/src/Serilog/Parsing/PropertyToken.cs +++ b/src/Serilog/Parsing/PropertyToken.cs @@ -13,17 +13,12 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.IO; using Serilog.Events; -#if NET40 -using IPropertyDictionary = System.Collections.Generic.IDictionary; -#else -using IPropertyDictionary = System.Collections.Generic.IReadOnlyDictionary; -#endif - namespace Serilog.Parsing { /// @@ -88,7 +83,7 @@ public PropertyToken(string propertyName, string rawText, string format = null, /// Properties that may be represented by the token. /// Output for the rendered string. /// Supplies culture-specific formatting information, or null. - public override void Render(IPropertyDictionary properties, TextWriter output, IFormatProvider formatProvider = null) + public override void Render(IReadOnlyDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { if (properties == null) throw new ArgumentNullException(nameof(properties)); if (output == null) throw new ArgumentNullException(nameof(output)); diff --git a/src/Serilog/Parsing/TextToken.cs b/src/Serilog/Parsing/TextToken.cs index 6a464cfe8..9035d57d1 100644 --- a/src/Serilog/Parsing/TextToken.cs +++ b/src/Serilog/Parsing/TextToken.cs @@ -13,13 +13,9 @@ // limitations under the License. using System; +using System.Collections.Generic; using System.IO; - -#if NET40 -using IPropertyDictionary = System.Collections.Generic.IDictionary; -#else -using IPropertyDictionary = System.Collections.Generic.IReadOnlyDictionary; -#endif +using Serilog.Events; namespace Serilog.Parsing { @@ -51,7 +47,7 @@ public TextToken(string text, int startIndex = -1) : base(startIndex) /// Properties that may be represented by the token. /// Output for the rendered string. /// Supplies culture-specific formatting information, or null. - public override void Render(IPropertyDictionary properties, TextWriter output, IFormatProvider formatProvider = null) + public override void Render(IReadOnlyDictionary properties, TextWriter output, IFormatProvider formatProvider = null) { if (output == null) throw new ArgumentNullException(nameof(output)); output.Write(Text); diff --git a/src/Serilog/Policies/EnumScalarConversionPolicy.cs b/src/Serilog/Policies/EnumScalarConversionPolicy.cs index 78463d87a..2a215cba4 100644 --- a/src/Serilog/Policies/EnumScalarConversionPolicy.cs +++ b/src/Serilog/Policies/EnumScalarConversionPolicy.cs @@ -14,12 +14,7 @@ using Serilog.Core; using Serilog.Events; - -#if NET40 -using Serilog.Platform; -#else using System.Reflection; -#endif namespace Serilog.Policies { diff --git a/src/Serilog/Policies/NullableScalarConversionPolicy.cs b/src/Serilog/Policies/NullableScalarConversionPolicy.cs index bb756d273..e4a19f138 100644 --- a/src/Serilog/Policies/NullableScalarConversionPolicy.cs +++ b/src/Serilog/Policies/NullableScalarConversionPolicy.cs @@ -23,25 +23,13 @@ class NullableScalarConversionPolicy : IScalarConversionPolicy public bool TryConvertToScalar(object value, ILogEventPropertyValueFactory propertyValueFactory, out ScalarValue result) { var type = value.GetType(); - if (! -#if NET40 - type.IsGenericType -#else - type.IsConstructedGenericType -#endif - || type.GetGenericTypeDefinition() != typeof(Nullable<>)) + if (!type.IsConstructedGenericType || type.GetGenericTypeDefinition() != typeof(Nullable<>)) { result = null; return false; } - var targetType = -#if NET40 - type.GetGenericArguments() -#else - type.GenericTypeArguments -#endif - [0]; + var targetType = type.GenericTypeArguments[0]; var innerValue = Convert.ChangeType(value, targetType); result = propertyValueFactory.CreatePropertyValue(innerValue) as ScalarValue; diff --git a/src/Serilog/Properties/AssemblyInfo.cs b/src/Serilog/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..dd34d0bdb --- /dev/null +++ b/src/Serilog/Properties/AssemblyInfo.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/Settings/KeyValuePairs/KeyValuePairSettings.cs b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs index a50f02be4..6ee49adce 100644 --- a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs +++ b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs @@ -21,10 +21,6 @@ using Serilog.Configuration; using Serilog.Events; -#if NET40 -using Serilog.Platform; -#endif - namespace Serilog.Settings.KeyValuePairs { class KeyValuePairSettings : ILoggerSettings @@ -119,19 +115,13 @@ where er.Key.StartsWith(EnrichWithEventEnricherPrefix) && !er.Key.StartsWith(Enr } } - private static void ApplyDirectives(List> directives, IList configurationMethods, object loggerConfigMethod) + static void ApplyDirectives(List> directives, IList configurationMethods, object loggerConfigMethod) { foreach (var directiveInfo in directives) { var target = configurationMethods .Where(m => m.Name == directiveInfo.Key && - m.GetParameters().Skip(1).All(p => -#if NET40 - (p.Attributes & ParameterAttributes.HasDefault) != ParameterAttributes.None -#else - p.HasDefaultValue -#endif - || directiveInfo.Any(s => s.Argument == p.Name))) + m.GetParameters().Skip(1).All(p => p.HasDefaultValue || directiveInfo.Any(s => s.Argument == p.Name))) .OrderByDescending(m => m.GetParameters().Length) .FirstOrDefault(); @@ -221,13 +211,9 @@ internal static IList FindEventEnricherConfigurationMethods(IEnumera internal static IList FindConfigurationMethods(IEnumerable configurationAssemblies, Type configType) { return configurationAssemblies - .SelectMany(a => a. -#if NET40 - GetExportedTypes() -#else - ExportedTypes -#endif - .Select(t => t.GetTypeInfo()).Where(t => t.IsSealed && t.IsAbstract && !t.IsNested)) + .SelectMany(a => a.ExportedTypes + .Select(t => t.GetTypeInfo()) + .Where(t => t.IsSealed && t.IsAbstract && !t.IsNested)) .SelectMany(t => t.DeclaredMethods) .Where(m => m.IsStatic && m.IsPublic && m.IsDefined(typeof(ExtensionAttribute), false)) .Where(m => m.GetParameters()[0].ParameterType == configType) diff --git a/src/Serilog/project.json b/src/Serilog/project.json index 15e1f78b5..40a306743 100644 --- a/src/Serilog/project.json +++ b/src/Serilog/project.json @@ -1,64 +1,58 @@ { - "version": "2.0.0-beta-*", - "description": "Simple .NET logging with fully-structured events", - "authors": [ "Serilog Contributors" ], - "tags": [ "serilog", "logging", "semantic", "structured" ], - "projectUrl": "http://serilog.net", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", - "iconUrl": "http://serilog.net/images/serilog-nuget.png", - "frameworks": { - "net45": { - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "REMOTING" ] - }, - "frameworkAssemblies": { - "System.Configuration": "" - } - }, - "dotnet5.1": { - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk", - "define": [ "NO_APPDOMAIN" ] - }, - "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-23516", - "System.Console": "4.0.0-beta-23516", - "System.Diagnostics.TraceSource": "4.0.0-beta-23516", - "System.Globalization": "4.0.11-beta-23516", - "System.IO": "4.0.11-beta-23516", - "System.Linq": "4.0.1-beta-23516", - "System.Reflection.Extensions": "4.0.1-beta-23516", - "System.Runtime.Extensions": "4.0.11-beta-23516", - "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", - "System.Text.RegularExpressions": "4.0.11-beta-23516", - "System.Threading": "4.0.11-beta-23516", - "System.Threading.Thread": "4.0.0-beta-23516" - } - }, - "dotnet5.4": { - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk", - "define": [ "ASYNCLOCAL", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "NO_TIMER", "NO_APPDOMAIN", "USERNAMEFROMENV" ] - - }, - "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-23516", - "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.Globalization": "4.0.11-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.Reflection.Extensions": "4.0.1-beta-23516", - "System.Runtime.Extensions": "4.0.11-beta-23516", - "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", - "System.Text.RegularExpressions": "4.0.11-beta-23516", - "System.Threading": "4.0.11-beta-23516", - "System.Threading.Thread": "4.0.0-beta-23516" - } - } + "version": "2.0.0-beta-*", + "description": "Simple .NET logging with fully-structured events", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "logging", "semantic", "structured" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-nuget.png", + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworks": { + "net45": { + "compilationOptions": { + "define": [ "PROCESS", "REMOTING", "APPDOMAIN" ] + } + }, + "dotnet5.1": { + "dependencies": { + "Microsoft.CSharp": "4.0.1-beta-23516", + "System.Console": "4.0.0-beta-23516", + "System.Diagnostics.TraceSource": "4.0.0-beta-23516", + "System.Globalization": "4.0.11-beta-23516", + "System.IO": "4.0.11-beta-23516", + "System.Linq": "4.0.1-beta-23516", + "System.Reflection.Extensions": "4.0.1-beta-23516", + "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", + "System.Text.RegularExpressions": "4.0.11-beta-23516", + "System.Threading": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516" + } + }, + "dotnet5.4": { + "compilationOptions": { + "define": [ "ASYNCLOCAL", "PROCESS", "USERNAMEFROMENV" ] + + }, + "dependencies": { + "Microsoft.CSharp": "4.0.1-beta-23516", + "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.Globalization": "4.0.11-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.Reflection.Extensions": "4.0.1-beta-23516", + "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", + "System.Text.RegularExpressions": "4.0.11-beta-23516", + "System.Threading": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516" + } } + } } diff --git a/test/Serilog.Tests/Context/LogContextTests-net40.cs b/test/Serilog.Tests/Context/LogContextTests-net40.cs deleted file mode 100644 index e7ab93f87..000000000 --- a/test/Serilog.Tests/Context/LogContextTests-net40.cs +++ /dev/null @@ -1,41 +0,0 @@ -#if NET40 -using Xunit; -using Serilog.Context; -using Serilog.Events; -using Serilog.Tests.Support; - -namespace Serilog.Tests.Context -{ - public class LogContextTests - { - [Fact] - public void MoreNestedPropertiesOverrideLessNestedOnes() - { - LogEvent lastEvent = null; - - var log = new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.Sink(new DelegatingSink(e => lastEvent = e)) - .CreateLogger(); - - using (LogContext.PushProperty("A", 1)) - { - log.Write(Some.InformationEvent()); - Assert.Equal(1, lastEvent.Properties["A"].LiteralValue()); - - using (LogContext.PushProperty("A", 2)) - { - log.Write(Some.InformationEvent()); - Assert.Equal(2, lastEvent.Properties["A"].LiteralValue()); - } - - log.Write(Some.InformationEvent()); - Assert.Equal(1, lastEvent.Properties["A"].LiteralValue()); - } - - log.Write(Some.InformationEvent()); - Assert.False(lastEvent.Properties.ContainsKey("A")); - } - } -} -#endif \ No newline at end of file diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index 980ad9535..efcf71422 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -145,7 +145,7 @@ public async Task ContextPropertiesPersistWhenCrossAppDomainCallsAreEnabled() } #endif -#if !NO_APPDOMAIN +#if APPDOMAIN // Must not actually try to pass context across domains, // since user property types may not be serializable. // Fails if the Serilog assemblies cannot be loaded in the diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 540b93591..f9c0178a7 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -1,54 +1,57 @@ { - "version": "2.0.0-beta-*", - "commands": { - "test": "xunit.runner.dnx", - "test-dnxcore50": "xunit.runner.dnx" + "version": "2.0.0-beta-*", + "commands": { + "test": "xunit.runner.dnx", + "test-dnxcore50": "xunit.runner.dnx" + }, + "dependencies": { + "Newtonsoft.Json": "7.0.1", + "Rx-Main": "2.2.5", + "Serilog": { "target": "project" }, + "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.Trace": { "target": "project" }, + "Serilog.Sinks.File": { "target": "project" }, + "Serilog.Sinks.RollingFile": { "target": "project" }, + "Serilog.Sinks.PeriodicBatching": { "target": "project" }, + "Serilog.Sinks.Observable": { "target": "project" }, + "Serilog.Sinks.TextWriter": { "target": "project" } + }, + "frameworks": { + "dnx452": { + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk", + "define": [ "APPSETTINGS", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING", "APPDOMAIN" ] + }, + "frameworkAssemblies": { + "System.Configuration": "" + }, + "dependencies": { + "Serilog.Settings.AppSettings": { "target": "project" } + } }, - "dependencies": { - "Newtonsoft.Json": "7.0.1", - "Rx-Main": "2.2.5", - "Serilog": { "target": "project" }, - "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.Trace": { "target": "project" }, - "Serilog.Sinks.File": { "target": "project" }, - "Serilog.Sinks.RollingFile": { "target": "project" }, - "Serilog.Sinks.PeriodicBatching": { "target": "project" }, - "Serilog.Sinks.Observable": { "target": "project" }, - "Serilog.Sinks.TextWriter": {"target": "project"} - }, - "frameworks": { - "dnx452": { - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING" ] - }, - "frameworkAssemblies": { - "System.Configuration": "" - } - }, - "dnxcore50": { - "compilationOptions": { - "define": [ "ASYNCLOCAL", "FILE_IO", "PERIODIC_BATCHING", "NO_APPDOMAIN" ] - }, - "dependencies": { - "Microsoft.CSharp": "4.0.1-beta-23516", - "System.Collections": "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.Dynamic.Runtime": "4.0.11-beta-23516", - "System.IO.FileSystem": "4.0.1-beta-23516", - "System.Linq": "4.0.1-beta-23516", - "System.Runtime": "4.0.21-beta-23516", - "System.Runtime.Extensions": "4.0.11-beta-23516", - "System.Text.RegularExpressions": "4.0.11-beta-23516", - "System.Threading": "4.0.11-beta-23516", - "System.Threading.Thread": "4.0.0-beta-23516", - "System.Threading.Timer": "4.0.1-beta-23516" - } - } + "dnxcore50": { + "compilationOptions": { + "define": [ "ASYNCLOCAL", "FILE_IO", "PERIODIC_BATCHING" ] + }, + "dependencies": { + "Microsoft.CSharp": "4.0.1-beta-23516", + "System.Collections": "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.Dynamic.Runtime": "4.0.11-beta-23516", + "System.IO.FileSystem": "4.0.1-beta-23516", + "System.Linq": "4.0.1-beta-23516", + "System.Runtime": "4.0.21-beta-23516", + "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Text.RegularExpressions": "4.0.11-beta-23516", + "System.Threading": "4.0.11-beta-23516", + "System.Threading.Thread": "4.0.0-beta-23516", + "System.Threading.Timer": "4.0.1-beta-23516" + } } + } }