From 406fa3d6b90820a59c2be2ac57a8268ca2fb77a7 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sat, 7 Dec 2019 19:30:02 +0300 Subject: [PATCH 1/4] Add support for custom types in arrays and custom collections add new test platforms and unify msbuild conditional properties minor code cleanup PackageIcon instead of PackageIconUrl fix for simplified syntax on netcore3.0 fix SinkWithConfigurationBindingArgument test (wrong argument type) --- Build.ps1 | 8 +- README.md | 2 +- appveyor.yml | 2 +- assets/icon.png | Bin 0 -> 22995 bytes .../Serilog.Settings.Configuration.csproj | 16 ++-- .../Assemblies/AssemblyFinder.cs | 13 ++-- .../Assemblies/DllScanningAssemblyFinder.cs | 2 +- .../Configuration/ConfigurationReader.cs | 54 +++++++------- .../Configuration/ObjectArgumentValue.cs | 70 +++++++++++++++++- .../ConfigurationSettingsTests.cs | 40 ++++++++++ .../DllScanningAssemblyFinderTests.cs | 2 +- ...erilog.Settings.Configuration.Tests.csproj | 16 ++-- .../Support/DelegatingSink.cs | 3 +- .../Support/Extensions.cs | 10 +++ .../Support/JsonStringConfigSource.cs | 2 +- .../DummyLoggerConfigurationExtensions.cs | 35 +++++++-- test/TestDummies/DummyPolicy.cs | 48 ++++++++++++ test/TestDummies/TestDummies.csproj | 7 +- 18 files changed, 259 insertions(+), 71 deletions(-) create mode 100644 assets/icon.png create mode 100644 test/TestDummies/DummyPolicy.cs diff --git a/Build.ps1 b/Build.ps1 index 4830b07..0221e67 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -2,7 +2,7 @@ echo "build: Build started" Push-Location $PSScriptRoot -if(Test-Path .\artifacts) { +if (Test-Path .\artifacts) { echo "build: Cleaning .\artifacts" Remove-Item .\artifacts -Force -Recurse } @@ -21,7 +21,7 @@ foreach ($src in ls src/*) { echo "build: Packaging project in $src" & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --include-source - if($LASTEXITCODE -ne 0) { exit 1 } + if ($LASTEXITCODE -ne 0) { exit 1 } Pop-Location } @@ -32,7 +32,7 @@ foreach ($test in ls test/*.PerformanceTests) { echo "build: Building performance test project in $test" & dotnet build -c Release - if($LASTEXITCODE -ne 0) { exit 2 } + if ($LASTEXITCODE -ne 0) { exit 2 } Pop-Location } @@ -43,7 +43,7 @@ foreach ($test in ls test/*.Tests) { echo "build: Testing project in $test" & dotnet test -c Release - if($LASTEXITCODE -ne 0) { exit 3 } + if ($LASTEXITCODE -ne 0) { exit 3 } Pop-Location } diff --git a/README.md b/README.md index cc443b4..7c59c2e 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ If a Serilog package requires additional external configuration information (for ### Complex parameter value binding -When the configuration specifies a discrete value for a parameter (such as a string literal), the package will attempt to convert that value to the target method's declared CLR type of the parameter. Additional explicit handling is provided for parsing strings to `Uri` and `TimeSpan` objects and `enum` elements. +When the configuration specifies a discrete value for a parameter (such as a string literal), the package will attempt to convert that value to the target method's declared CLR type of the parameter. Additional explicit handling is provided for parsing strings to `Uri`, `TimeSpan`, `enum` and arrays. If the parameter value is not a discrete value, the package will use the configuration binding system provided by _Microsoft.Extensions.Options.ConfigurationExtensions_ to attempt to populate the parameter. Almost anything that can be bound by `IConfiguration.Get` should work with this package. An example of this is the optional `List` parameter used to configure the .NET Standard version of the _Serilog.Sinks.MSSqlServer_ package. diff --git a/appveyor.yml b/appveyor.yml index 396e0ef..f7194df 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: '{build}' skip_tags: true -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: Release build_script: - ps: ./Build.ps1 diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..0ffa0195b647acbe1a6ca1f4fe621915c21a6322 GIT binary patch literal 22995 zcma%jbyU@B)aIePJETEcP)ekcl2RIJ5T#2%P`VpwRHPA5Qo1_?l@J8!l$H?b`1ZLo zv)24KbJw~{Imh#>cfZemVjm(OYA6xl(&8cz2m%%5`&tMD3j7rXfsF}&7`qicg+I`r z%c5Pa@!F92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4{ zS=;c1mqJOpe7Ui^Tc9$QZ{SN|ZZ03ZDtFe1WiAJHM_U^k3%01<;jm#1It1~2Z*naa zgvW?mv*Y3x_Y2rO2F5R3Sq~nQ8FACgD=Wu4jg6Ze-(DN|k$O&JZR0G?amOaRuYRO8 zI5b>odmr=Ry;os)b+G+$w51}$?1||e3vOzv=?#k;V53hPMFRyAeGy^uTMiA2czM9` zvA)kAjarayZ!Hw6$@u#X8^?Ux(b3r6&i+eH&Fp#N2enO_($KR6Wn?aZy*J*F))Z;; z=jXugE3_yX;9V+Rfh=Q7MH6uImo8uS4LcGL6qE$RkI>&U4*MMYx(EMU(l`9F(W>(T%K literal 0 HcmV?d00001 diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index 22d6aea..5da0fb2 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -1,10 +1,11 @@ - + Microsoft.Extensions.Configuration (appsettings.json) support for Serilog. 3.1.1 + latest Serilog Contributors - netstandard2.0;net451;net461 + netstandard2.0;net451;net452;net461 true true Serilog.Settings.Configuration @@ -13,7 +14,7 @@ true Serilog.Settings.Configuration serilog;json - https://serilog.net/images/serilog-configuration-nuget.png + icon.png https://github.com/serilog/serilog-settings-configuration Apache-2.0 https://github.com/serilog/serilog-settings-configuration @@ -21,20 +22,21 @@ Serilog - + $(DefineConstants);PRIVATE_BIN + - - + + - + diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs index 4d356a8..0dba18f 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AssemblyFinder.cs @@ -27,15 +27,12 @@ public static AssemblyFinder Auto() public static AssemblyFinder ForSource(ConfigurationAssemblySource configurationAssemblySource) { - switch (configurationAssemblySource) + return configurationAssemblySource switch { - case ConfigurationAssemblySource.UseLoadedAssemblies: - return Auto(); - case ConfigurationAssemblySource.AlwaysScanDllFiles: - return new DllScanningAssemblyFinder(); - default: - throw new ArgumentOutOfRangeException(nameof(configurationAssemblySource), configurationAssemblySource, null); - } + ConfigurationAssemblySource.UseLoadedAssemblies => Auto(), + ConfigurationAssemblySource.AlwaysScanDllFiles => new DllScanningAssemblyFinder(), + _ => throw new ArgumentOutOfRangeException(nameof(configurationAssemblySource), configurationAssemblySource, null), + }; } public static AssemblyFinder ForDependencyContext(DependencyContext dependencyContext) diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs index 95584e2..102b492 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs @@ -50,7 +50,7 @@ where IsCaseInsensitiveMatch(assemblyFileName, nameToFind) return query.ToList().AsReadOnly(); - AssemblyName TryGetAssemblyNameFrom(string path) + static AssemblyName TryGetAssemblyNameFrom(string path) { try { diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index 3bf16df..29a13cf 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -220,39 +220,14 @@ internal ILookup> GetMet select new { Name = argument.Key, - Value = GetArgumentValue(argument) + Value = GetArgumentValue(argument, _configurationAssemblies) }).ToDictionary(p => p.Name, p => p.Value) select new { Name = name, Args = callArgs })) .ToLookup(p => p.Name, p => p.Args); return result; - IConfigurationArgumentValue GetArgumentValue(IConfigurationSection argumentSection) - { - IConfigurationArgumentValue argumentValue; - - // Reject configurations where an element has both scalar and complex - // values as a result of reading multiple configuration sources. - if (argumentSection.Value != null && argumentSection.GetChildren().Any()) - throw new InvalidOperationException( - $"The value for the argument '{argumentSection.Path}' is assigned different value " + - "types in more than one configuration source. Ensure all configurations consistently " + - "use either a scalar (int, string, boolean) or a complex (array, section, list, " + - "POCO, etc.) type for this argument value."); - - if (argumentSection.Value != null) - { - argumentValue = new StringArgumentValue(argumentSection.Value); - } - else - { - argumentValue = new ObjectArgumentValue(argumentSection, _configurationAssemblies); - } - - return argumentValue; - } - - string GetSectionName(IConfigurationSection s) + static string GetSectionName(IConfigurationSection s) { var name = s.GetSection("Name"); if (name.Value == null) @@ -262,6 +237,31 @@ string GetSectionName(IConfigurationSection s) } } + internal static IConfigurationArgumentValue GetArgumentValue(IConfigurationSection argumentSection, IReadOnlyCollection configurationAssemblies) + { + IConfigurationArgumentValue argumentValue; + + // Reject configurations where an element has both scalar and complex + // values as a result of reading multiple configuration sources. + if (argumentSection.Value != null && argumentSection.GetChildren().Any()) + throw new InvalidOperationException( + $"The value for the argument '{argumentSection.Path}' is assigned different value " + + "types in more than one configuration source. Ensure all configurations consistently " + + "use either a scalar (int, string, boolean) or a complex (array, section, list, " + + "POCO, etc.) type for this argument value."); + + if (argumentSection.Value != null) + { + argumentValue = new StringArgumentValue(argumentSection.Value); + } + else + { + argumentValue = new ObjectArgumentValue(argumentSection, configurationAssemblies); + } + + return argumentValue; + } + static IReadOnlyCollection LoadConfigurationAssemblies(IConfigurationSection section, AssemblyFinder assemblyFinder) { var assemblies = new Dictionary(); diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs index 6b54c34..e1730d2 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs @@ -1,10 +1,10 @@ using Microsoft.Extensions.Configuration; +using Serilog.Configuration; using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; -using Serilog.Configuration; - namespace Serilog.Settings.Configuration { class ObjectArgumentValue : IConfigurationArgumentValue @@ -47,8 +47,72 @@ public object ConvertTo(Type toType, ResolutionContext resolutionContext) } } - // MS Config binding + if (toType.IsArray) + return CreateArray(); + + if (IsContainer(toType, out var elementType) && TryCreateContainer(out var result)) + return result; + + // MS Config binding can work with a limited set of primitive types and collections return _section.Get(toType); + + object CreateArray() + { + var elementType = toType.GetElementType(); + var configurationElements = _section.GetChildren().ToArray(); + var result = Array.CreateInstance(elementType, configurationElements.Length); + for (int i = 0; i < configurationElements.Length; ++i) + { + var argumentValue = ConfigurationReader.GetArgumentValue(configurationElements[i], _configurationAssemblies); + var value = argumentValue.ConvertTo(elementType, resolutionContext); + result.SetValue(value, i); + } + + return result; + } + + bool TryCreateContainer(out object result) + { + result = null; + + if (toType.GetConstructor(Type.EmptyTypes) == null) + return false; + + // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers + var addMethod = toType.GetMethods().FirstOrDefault(m => !m.IsStatic && m.Name == "Add" && m.GetParameters()?.Length == 1 && m.GetParameters()[0].ParameterType == elementType); + if (addMethod == null) + return false; + + var configurationElements = _section.GetChildren().ToArray(); + result = Activator.CreateInstance(toType); + + for (int i = 0; i < configurationElements.Length; ++i) + { + var argumentValue = ConfigurationReader.GetArgumentValue(configurationElements[i], _configurationAssemblies); + var value = argumentValue.ConvertTo(elementType, resolutionContext); + addMethod.Invoke(result, new object[] { value }); + } + + return true; + } + } + + private static bool IsContainer(Type type, out Type elementType) + { + elementType = null; + foreach (var iface in type.GetInterfaces()) + { + if (iface.IsGenericType) + { + if (iface.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + { + elementType = iface.GetGenericArguments()[0]; + return true; + } + } + } + + return false; } } } diff --git a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs index 06352b7..5c513a9 100644 --- a/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs @@ -615,6 +615,46 @@ public void SinkWithStringArrayArgument() Assert.Equal(1, DummyRollingFileSink.Emitted.Count); } + [Fact] + public void DestructureWithCollectionsOfTypeArgument() + { + var json = @"{ + ""Serilog"": { + ""Using"": [ ""TestDummies"" ], + ""Destructure"": [{ + ""Name"": ""DummyArrayOfType"", + ""Args"": { + ""list"": [ + ""System.Byte"", + ""System.Int16"" + ], + ""array"" : [ + ""System.Int32"", + ""System.String"" + ], + ""type"" : ""System.TimeSpan"", + ""custom"" : [ + ""System.Int64"" + ], + ""customString"" : [ + ""System.UInt32"" + ] + } + }] + } + }"; + + DummyPolicy.Current = null; + + ConfigFromJson(json); + + Assert.Equal(typeof(TimeSpan), DummyPolicy.Current.Type); + Assert.Equal(new[] { typeof(int), typeof(string) }, DummyPolicy.Current.Array); + Assert.Equal(new[] { typeof(byte), typeof(short) }, DummyPolicy.Current.List); + Assert.Equal(typeof(long), DummyPolicy.Current.Custom.First); + Assert.Equal("System.UInt32", DummyPolicy.Current.CustomStrings.First); + } + [Fact] public void SinkWithIntArrayArgument() { diff --git a/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs b/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs index d8ab19a..be937a2 100644 --- a/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs +++ b/test/Serilog.Settings.Configuration.Tests/DllScanningAssemblyFinderTests.cs @@ -65,7 +65,7 @@ public void ShouldProbePrivateBinPath() AppDomain.Unload(ad); } - void DoTestInner() + static void DoTestInner() { var assemblyNames = new DllScanningAssemblyFinder().FindAssembliesContainingName("customSink"); Assert.Equal(2, assemblyNames.Count); diff --git a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj index 69ceb38..00f1c75 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -12,14 +12,15 @@ --> - net452;netcoreapp2.0 + latest + netcoreapp3.0;netcoreapp2.2;netcoreapp2.0;net452;net451 Serilog.Settings.Configuration.Tests ../../assets/Serilog.snk true true - + $(DefineConstants);PRIVATE_BIN @@ -28,14 +29,17 @@ - + - + - + - + + + + diff --git a/test/Serilog.Settings.Configuration.Tests/Support/DelegatingSink.cs b/test/Serilog.Settings.Configuration.Tests/Support/DelegatingSink.cs index 710d0c8..07a848b 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/DelegatingSink.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/DelegatingSink.cs @@ -10,8 +10,7 @@ public class DelegatingSink : ILogEventSink public DelegatingSink(Action write) { - if (write == null) throw new ArgumentNullException(nameof(write)); - _write = write; + _write = write ?? throw new ArgumentNullException(nameof(write)); } public void Emit(LogEvent logEvent) diff --git a/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs b/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs index 02e3487..571ff0c 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs @@ -8,5 +8,15 @@ public static object LiteralValue(this LogEventPropertyValue @this) { return ((ScalarValue)@this).Value; } + + // netcore3.0 error: + // Could not parse the JSON file. System.Text.Json.JsonReaderException : ''' is an invalid start of a property name. Expected a '"' + public static string ToValidJson(this string str) + { +#if NETCOREAPP3_0 + str = str.Replace('\'', '"'); +#endif + return str; + } } } diff --git a/test/Serilog.Settings.Configuration.Tests/Support/JsonStringConfigSource.cs b/test/Serilog.Settings.Configuration.Tests/Support/JsonStringConfigSource.cs index 31cf8ac..1175ee4 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/JsonStringConfigSource.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/JsonStringConfigSource.cs @@ -45,7 +45,7 @@ public JsonStringConfigProvider(string json) : base(new JsonConfigurationSource public override void Load() { - Load(StringToStream(_json)); + Load(StringToStream(_json.ToValidJson())); } static Stream StringToStream(string str) diff --git a/test/TestDummies/DummyLoggerConfigurationExtensions.cs b/test/TestDummies/DummyLoggerConfigurationExtensions.cs index ecae9cd..7c1d109 100644 --- a/test/TestDummies/DummyLoggerConfigurationExtensions.cs +++ b/test/TestDummies/DummyLoggerConfigurationExtensions.cs @@ -1,13 +1,13 @@ -using System; +using Microsoft.Extensions.Configuration; using Serilog; -using Serilog.Events; -using Serilog.Formatting; using Serilog.Configuration; using Serilog.Core; +using Serilog.Events; +using Serilog.Formatting; +using System; +using System.Collections.Generic; using TestDummies.Console; using TestDummies.Console.Themes; -using Microsoft.Extensions.Configuration; -using System.Collections.Generic; namespace TestDummies { @@ -63,13 +63,20 @@ public static LoggerConfiguration DummyWithConfigSection( public static LoggerConfiguration DummyRollingFile( this LoggerSinkConfiguration loggerSinkConfiguration, - List objectBinding, + List objectBinding, string pathFormat, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum) { return loggerSinkConfiguration.Sink(new DummyRollingFileSink(), restrictedToMinimumLevel); } + public class Binding + { + public string Foo { get; set; } + + public string Abc { get; set; } + } + public static LoggerConfiguration DummyRollingFile( this LoggerSinkConfiguration loggerSinkConfiguration, string[] stringArrayBinding, @@ -133,5 +140,21 @@ string hardCodedString return loggerDestructuringConfiguration.With(new DummyHardCodedStringDestructuringPolicy(hardCodedString)); } + public static LoggerConfiguration DummyArrayOfType(this LoggerDestructuringConfiguration loggerSinkConfiguration, + List list, + Type[] array = null, + Type type = null, + CustomCollection custom = null, + CustomCollection customString = null) + { + return loggerSinkConfiguration.With(DummyPolicy.Current = new DummyPolicy + { + List = list, + Array = array, + Type = type, + Custom = custom, + CustomStrings = customString, + }); + } } } diff --git a/test/TestDummies/DummyPolicy.cs b/test/TestDummies/DummyPolicy.cs new file mode 100644 index 0000000..ada4c2f --- /dev/null +++ b/test/TestDummies/DummyPolicy.cs @@ -0,0 +1,48 @@ +using Serilog.Core; +using Serilog.Events; +using System; +using System.Collections; +using System.Collections.Generic; + +namespace TestDummies +{ + public class DummyPolicy : IDestructuringPolicy + { + public static DummyPolicy Current { get; set; } + + public Type[] Array { get; set; } + + public List List { get; set; } + + public CustomCollection Custom { get; set; } + + public CustomCollection CustomStrings { get; set; } + + public Type Type { get; set; } + + public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result) + { + result = null; + return false; + } + } + + public class CustomCollection : IEnumerable + { + private readonly List inner = new List(); + + public void Add(T item) => inner.Add(item); + + // wrong signature for collection initializer + public int Add() => 0; + + // wrong signature for collection initializer + public void Add(string a, byte b) { } + + public T First => inner.Count > 0 ? inner[0] : default; + + public IEnumerator GetEnumerator() => inner.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => inner.GetEnumerator(); + } +} diff --git a/test/TestDummies/TestDummies.csproj b/test/TestDummies/TestDummies.csproj index 5c212f5..b6be4b2 100644 --- a/test/TestDummies/TestDummies.csproj +++ b/test/TestDummies/TestDummies.csproj @@ -1,7 +1,8 @@  - net452;netstandard2.0 + latest + net451;net452;netstandard2.0 TestDummies ../../assets/Serilog.snk true @@ -20,10 +21,10 @@ - + - + From b4a47f468663fecee78373556d6bd903ae135d65 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sat, 21 Mar 2020 16:06:56 +0300 Subject: [PATCH 2/4] revert csproj changes --- .../Serilog.Settings.Configuration.csproj | 10 +++++----- .../Serilog.Settings.Configuration.Tests.csproj | 15 ++++++--------- test/TestDummies/TestDummies.csproj | 6 +++--- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj index 5da0fb2..a911be3 100644 --- a/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj +++ b/src/Serilog.Settings.Configuration/Serilog.Settings.Configuration.csproj @@ -5,7 +5,7 @@ 3.1.1 latest Serilog Contributors - netstandard2.0;net451;net452;net461 + netstandard2.0;net451;net461 true true Serilog.Settings.Configuration @@ -22,7 +22,7 @@ Serilog - + $(DefineConstants);PRIVATE_BIN @@ -32,11 +32,11 @@ - - + + - + diff --git a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj index 00f1c75..7717419 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -12,15 +12,15 @@ --> + net452;netcoreapp2.0 latest - netcoreapp3.0;netcoreapp2.2;netcoreapp2.0;net452;net451 Serilog.Settings.Configuration.Tests ../../assets/Serilog.snk true true - + $(DefineConstants);PRIVATE_BIN @@ -29,17 +29,14 @@ - + - + - + - - - - + diff --git a/test/TestDummies/TestDummies.csproj b/test/TestDummies/TestDummies.csproj index b6be4b2..6afefb4 100644 --- a/test/TestDummies/TestDummies.csproj +++ b/test/TestDummies/TestDummies.csproj @@ -2,7 +2,7 @@ latest - net451;net452;netstandard2.0 + net452;netstandard2.0 TestDummies ../../assets/Serilog.snk true @@ -21,10 +21,10 @@ - + - + From 1d11672c4b3dbdfb6153aa5a139ece3c4a074e9b Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sat, 21 Mar 2020 16:15:26 +0300 Subject: [PATCH 3/4] icon + tests --- serilog-settings-configuration.sln | 5 +++-- .../Serilog.Settings.Configuration.Tests.csproj | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/serilog-settings-configuration.sln b/serilog-settings-configuration.sln index 82c4512..9c064b2 100644 --- a/serilog-settings-configuration.sln +++ b/serilog-settings-configuration.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4E41FD57-5FAB-4E3C-B16E-463DE98338BC}" EndProject @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{62D0B9 appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md + assets\icon.png = assets\icon.png LICENSE = LICENSE README.md = README.md serilog-settings-configuration.sln.DotSettings = serilog-settings-configuration.sln.DotSettings diff --git a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj index 7717419..c432c1f 100644 --- a/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj +++ b/test/Serilog.Settings.Configuration.Tests/Serilog.Settings.Configuration.Tests.csproj @@ -12,7 +12,7 @@ --> - net452;netcoreapp2.0 + net452;netcoreapp2.0;netcoreapp3.1 latest Serilog.Settings.Configuration.Tests ../../assets/Serilog.snk @@ -39,6 +39,10 @@ + + + + From 33f20bb2d48d090e9af48002c16833a4dbb8877a Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sat, 21 Mar 2020 16:34:59 +0300 Subject: [PATCH 4/4] fix --- test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs b/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs index 571ff0c..e02d875 100644 --- a/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs +++ b/test/Serilog.Settings.Configuration.Tests/Support/Extensions.cs @@ -13,7 +13,7 @@ public static object LiteralValue(this LogEventPropertyValue @this) // Could not parse the JSON file. System.Text.Json.JsonReaderException : ''' is an invalid start of a property name. Expected a '"' public static string ToValidJson(this string str) { -#if NETCOREAPP3_0 +#if NETCOREAPP3_1 str = str.Replace('\'', '"'); #endif return str;