From 74319ecc77a48ae5fc6020b4f9e0bf7f29fc5688 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 5 May 2016 20:31:07 +1000 Subject: [PATCH] Remove Serilog.Settings.AppSettings, which is now at serilog/serilog-settings-appsettings. Also re-enabled KeyValuePairSettingsTests, excluding some duplication to let us scope back the enricher dependencies a bit. --- Serilog.sln | 9 +- ...ppSettingsLoggerConfigurationExtensions.cs | 53 ------ .../Properties/AssemblyInfo.cs | 14 -- .../Serilog.Settings.AppSettings.xproj | 21 --- .../AppSettings/AppSettingsSettings.cs | 45 ----- src/Serilog.Settings.AppSettings/project.json | 22 --- .../Settings/AppSettingsTests.cs | 176 ------------------ .../Settings/KeyValuePairSettingsTests.cs | 22 +-- test/Serilog.Tests/app.config | 16 -- test/Serilog.Tests/project.json | 12 +- 10 files changed, 9 insertions(+), 381 deletions(-) delete mode 100644 src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs delete mode 100644 src/Serilog.Settings.AppSettings/Properties/AssemblyInfo.cs delete mode 100644 src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj delete mode 100644 src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs delete mode 100644 src/Serilog.Settings.AppSettings/project.json delete mode 100644 test/Serilog.Tests/Settings/AppSettingsTests.cs delete mode 100644 test/Serilog.Tests/app.config diff --git a/Serilog.sln b/Serilog.sln index 167376949..b7043bd35 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}" EndProject @@ -21,8 +21,6 @@ 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.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 @@ -37,10 +35,6 @@ 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 - {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 @@ -48,6 +42,5 @@ Global GlobalSection(NestedProjects) = preSolution {803CD13A-D54B-4CEC-A55F-E22AE3D93B3C} = {037440DE-440B-4129-9F7A-09B42D00397E} {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {0D135C0C-A60B-454A-A2F4-CD74A30E04B0} - {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 deleted file mode 100644 index 28018e9ae..000000000 --- a/src/Serilog.Settings.AppSettings/AppSettingsLoggerConfigurationExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -// 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.Settings.AppSettings/Properties/AssemblyInfo.cs b/src/Serilog.Settings.AppSettings/Properties/AssemblyInfo.cs deleted file mode 100644 index 1237c0e24..000000000 --- a/src/Serilog.Settings.AppSettings/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyVersion("2.0.0.0")] - -[assembly: CLSCompliant(true)] - -[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" + - "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + - "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + - "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + - "94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + - "b19485ec")] diff --git a/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj b/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj deleted file mode 100644 index 1e99e05da..000000000 --- a/src/Serilog.Settings.AppSettings/Serilog.Settings.AppSettings.xproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - 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/Settings/AppSettings/AppSettingsSettings.cs b/src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs deleted file mode 100644 index 6850141a3..000000000 --- a/src/Serilog.Settings.AppSettings/Settings/AppSettings/AppSettingsSettings.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013-2015 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 System.Configuration; -using System.Linq; -using Serilog.Configuration; -using Serilog.Settings.KeyValuePairs; - -namespace Serilog.Settings.AppSettings -{ - class AppSettingsSettings : ILoggerSettings - { - readonly string _settingPrefix; - - public AppSettingsSettings(string settingPrefix = null) - { - _settingPrefix = settingPrefix == null ? "serilog:" : $"{settingPrefix}:serilog:"; - } - - public void Configure(LoggerConfiguration loggerConfiguration) - { - if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration)); - - var settings = ConfigurationManager.AppSettings; - - var pairs = settings.AllKeys - .Where(k => k.StartsWith(_settingPrefix)) - .ToDictionary(k => k.Substring(_settingPrefix.Length), k => Environment.ExpandEnvironmentVariables(settings[k])); - - loggerConfiguration.ReadFrom.KeyValuePairs(pairs); - } - } -} diff --git a/src/Serilog.Settings.AppSettings/project.json b/src/Serilog.Settings.AppSettings/project.json deleted file mode 100644 index 80c0bb062..000000000 --- a/src/Serilog.Settings.AppSettings/project.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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/test/Serilog.Tests/Settings/AppSettingsTests.cs b/test/Serilog.Tests/Settings/AppSettingsTests.cs deleted file mode 100644 index ed1aae1ab..000000000 --- a/test/Serilog.Tests/Settings/AppSettingsTests.cs +++ /dev/null @@ -1,176 +0,0 @@ -#if APPSETTINGS -using System; -using System.Configuration; -using Xunit; -using Serilog.Events; -using Serilog.Tests.Support; -using Serilog.Context; - -namespace Serilog.Tests.AppSettings.Tests -{ - public class AppSettingsTests - { - [Fact] - public void EnvironmentVariableExpansionIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.Equal("%PATH%", ConfigurationManager.AppSettings["serilog:enrich:with-property:Path"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - log.Information("Has a Path property with value expanded from the environment variable"); - - Assert.NotNull(evt); - Assert.NotEmpty((string)evt.Properties["Path"].LiteralValue()); - Assert.NotEqual("%PATH%", evt.Properties["Path"].LiteralValue()); - } - - [Fact] - public void CanUseCustomPrefixToConfigureSettings() - { - const string prefix1 = "custom1"; - const string prefix2 = "custom2"; - - // Make sure we have the expected keys in the App.config - Assert.Equal("Warning", ConfigurationManager.AppSettings[prefix1 + ":serilog:minimum-level"]); - Assert.Equal("Error", ConfigurationManager.AppSettings[prefix2 + ":serilog:minimum-level"]); - - var log1 = new LoggerConfiguration() - .WriteTo.Observers(o => { }) - .ReadFrom.AppSettings(prefix1) - .CreateLogger(); - - var log2 = new LoggerConfiguration() - .WriteTo.Observers(o => { }) - .ReadFrom.AppSettings(prefix2) - .CreateLogger(); - - Assert.False(log1.IsEnabled(LogEventLevel.Information)); - Assert.True(log1.IsEnabled(LogEventLevel.Warning)); - - Assert.False(log2.IsEnabled(LogEventLevel.Warning)); - Assert.True(log2.IsEnabled(LogEventLevel.Error)); - } - - [Fact] - public void CustomPrefixCannotContainColon() - { - Assert.Throws(() => - new LoggerConfiguration().ReadFrom.AppSettings("custom1:custom2")); - } - - [Fact] - public void CustomPrefixCannotBeSerilog() - { - Assert.Throws(() => - new LoggerConfiguration().ReadFrom.AppSettings("serilog")); - } - - [Fact] - public void ThreadIdEnricherIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.NotNull(ConfigurationManager.AppSettings["serilog:enrich:WithThreadId"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - log.Information("Has a ThreadId property with value generated by ThreadIdEnricher"); - - Assert.NotNull(evt); - Assert.NotNull(evt.Properties["ThreadId"]); - Assert.NotNull(evt.Properties["ThreadId"].LiteralValue() as int?); - } -#if !DOTNET5_1 - [Fact] - public void MachineNameEnricherIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.NotNull(ConfigurationManager.AppSettings["serilog:enrich:WithMachineName"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - log.Information("Has a MachineName property with value generated by MachineNameEnricher"); - - Assert.NotNull(evt); - Assert.NotNull(evt.Properties["MachineName"]); - Assert.NotEmpty((string)evt.Properties["MachineName"].LiteralValue()); - } - - [Fact] - public void EnrivonmentUserNameEnricherIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.NotNull(ConfigurationManager.AppSettings["serilog:enrich:WithEnvironmentUserName"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - log.Information("Has a EnrivonmentUserName property with value generated by EnrivonmentUserNameEnricher"); - - Assert.NotNull(evt); - Assert.NotNull(evt.Properties["EnvironmentUserName"]); - Assert.NotEmpty((string)evt.Properties["EnvironmentUserName"].LiteralValue()); - } -#endif - -#if PROCESS - [Fact] - public void ProcessIdEnricherIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.NotNull(ConfigurationManager.AppSettings["serilog:enrich:WithProcessId"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - log.Information("Has a ProcessId property with value generated by ProcessIdEnricher"); - - Assert.NotNull(evt); - Assert.NotNull(evt.Properties["ProcessId"]); - Assert.NotNull(evt.Properties["ProcessId"].LiteralValue() as int?); - } -#endif - - [Fact] - public void LogContextEnricherIsApplied() - { - // Make sure we have the expected key in the App.config - Assert.NotNull(ConfigurationManager.AppSettings["serilog:enrich:FromLogContext"]); - - LogEvent evt = null; - var log = new LoggerConfiguration() - .ReadFrom.AppSettings() - .WriteTo.Sink(new DelegatingSink(e => evt = e)) - .CreateLogger(); - - using (LogContext.PushProperty("A", 1)) - { - log.Information("Has a LogContext property with value generated by LogContextEnricher"); - } - - Assert.NotNull(evt); - Assert.NotNull(evt.Properties["A"]); - Assert.NotNull(evt.Properties["A"].LiteralValue() as int?); - Assert.Equal(1, (int)evt.Properties["A"].LiteralValue()); - } - } -} -#endif diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index 8cc02a966..fac2e0f3f 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -1,6 +1,4 @@ -#if APPSETTINGS - -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Xunit; @@ -64,12 +62,8 @@ public void FindsEventEnrichersWithinAnAssembly() var eventEnrichers = KeyValuePairSettings .FindEventEnricherConfigurationMethods(new[] { - typeof(Log).GetTypeInfo().Assembly -#if !DOTNET5_1 - , typeof(MachineNameEnricher).GetTypeInfo().Assembly - , typeof(ProcessIdEnricher).GetTypeInfo().Assembly -#endif - , typeof(ThreadIdEnricher).GetTypeInfo().Assembly + typeof(Log).GetTypeInfo().Assembly, + typeof(ThreadIdEnricher).GetTypeInfo().Assembly }) .Select(m => m.Name) .Distinct() @@ -77,13 +71,6 @@ public void FindsEventEnrichersWithinAnAssembly() Assert.True(eventEnrichers.Contains("FromLogContext")); -#if !DOTNET5_1 - Assert.True(eventEnrichers.Contains("WithEnvironmentUserName")); - Assert.True(eventEnrichers.Contains("WithMachineName")); -#endif -#if PROCESS - Assert.True(eventEnrichers.Contains("WithProcessId")); -#endif Assert.True(eventEnrichers.Contains("WithThreadId")); } @@ -105,5 +92,4 @@ public void PropertyEnrichmentIsApplied() Assert.Equal("Test", evt.Properties["App"].LiteralValue()); } } -} -#endif +} \ No newline at end of file diff --git a/test/Serilog.Tests/app.config b/test/Serilog.Tests/app.config deleted file mode 100644 index afad5d26f..000000000 --- a/test/Serilog.Tests/app.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 8104aa14a..3204861e8 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -20,17 +20,13 @@ "Serilog.Enrichers.Thread": "2.0.0-beta-519" }, + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, "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" } + "define": [ "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING", "APPDOMAIN" ] } }, "dnxcore50": {