From 38ef5f994814340fb39337a02359e6b6df7f3ced Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 24 Feb 2021 08:56:40 +1000 Subject: [PATCH] Update to .NET 5 SDK, re-enable .NET Framework (.NET Standard 2.0) support by excluding CreateBootstrapLogger()/ReloadableLogger on that platform --- global.json | 2 +- .../Extensions/Hosting/CachingReloadableLogger.cs | 6 +++++- .../Extensions/Hosting/ReloadableLogger.cs | 4 ++++ .../LoggerConfigurationExtensions.cs | 4 ++++ .../Serilog.Extensions.Hosting.csproj | 9 +++++++-- .../SerilogHostBuilderExtensions.cs | 10 ++++++++-- .../ReloadableLoggerTests.cs | 6 +++++- .../Serilog.Extensions.Hosting.Tests.csproj | 6 +++++- 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/global.json b/global.json index e3bbb00..14a6148 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "allowPrerelease": false, - "version": "3.1.100", + "version": "5.0.102", "rollForward": "latestFeature" } } diff --git a/src/Serilog.Extensions.Hosting/Extensions/Hosting/CachingReloadableLogger.cs b/src/Serilog.Extensions.Hosting/Extensions/Hosting/CachingReloadableLogger.cs index 9a47560..d20d9d6 100644 --- a/src/Serilog.Extensions.Hosting/Extensions/Hosting/CachingReloadableLogger.cs +++ b/src/Serilog.Extensions.Hosting/Extensions/Hosting/CachingReloadableLogger.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if !NO_RELOADABLE_LOGGER + using System; using System.Collections.Generic; using System.Threading; @@ -516,4 +518,6 @@ public bool BindProperty(string propertyName, object value, bool destructureObje return canBind; } } -} \ No newline at end of file +} + +#endif diff --git a/src/Serilog.Extensions.Hosting/Extensions/Hosting/ReloadableLogger.cs b/src/Serilog.Extensions.Hosting/Extensions/Hosting/ReloadableLogger.cs index 454b707..eb7a8d7 100644 --- a/src/Serilog.Extensions.Hosting/Extensions/Hosting/ReloadableLogger.cs +++ b/src/Serilog.Extensions.Hosting/Extensions/Hosting/ReloadableLogger.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if !NO_RELOADABLE_LOGGER + using System; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -667,3 +669,5 @@ internal bool CreateChild( } } } + +#endif diff --git a/src/Serilog.Extensions.Hosting/LoggerConfigurationExtensions.cs b/src/Serilog.Extensions.Hosting/LoggerConfigurationExtensions.cs index 2a78262..51a02d1 100644 --- a/src/Serilog.Extensions.Hosting/LoggerConfigurationExtensions.cs +++ b/src/Serilog.Extensions.Hosting/LoggerConfigurationExtensions.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if !NO_RELOADABLE_LOGGER + using Microsoft.Extensions.Hosting; using Serilog.Extensions.Hosting; using System; @@ -38,3 +40,5 @@ public static ReloadableLogger CreateBootstrapLogger(this LoggerConfiguration lo } } } + +#endif diff --git a/src/Serilog.Extensions.Hosting/Serilog.Extensions.Hosting.csproj b/src/Serilog.Extensions.Hosting/Serilog.Extensions.Hosting.csproj index 00c094d..f9e5562 100644 --- a/src/Serilog.Extensions.Hosting/Serilog.Extensions.Hosting.csproj +++ b/src/Serilog.Extensions.Hosting/Serilog.Extensions.Hosting.csproj @@ -2,9 +2,10 @@ Serilog support for .NET Core logging in hosted services - 4.0.1 + 4.1.0 Microsoft;Serilog Contributors - netstandard2.1 + netstandard2.0;netstandard2.1 + 8 true true Serilog.Extensions.Hosting @@ -22,6 +23,10 @@ Serilog + + $(DefineConstants);NO_RELOADABLE_LOGGER + + diff --git a/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs b/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs index 0863769..7764a2b 100644 --- a/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs +++ b/src/Serilog.Extensions.Hosting/SerilogHostBuilderExtensions.cs @@ -125,8 +125,8 @@ public static IHostBuilder UseSerilog( /// By default, Serilog does not write events to s registered through /// the Microsoft.Extensions.Logging API. Normally, equivalent Serilog sinks are used in place of providers. Specify /// true to write events to all providers. - /// If the static is a bootstrap logger (created using - /// ), and is + /// If the static is a bootstrap logger (see + /// LoggerConfigurationExtensions.CreateBootstrapLogger()), and is /// not specified, the the bootstrap logger will be reconfigured through the supplied delegate, rather than being /// replaced entirely or ignored. /// The host builder. @@ -140,8 +140,12 @@ public static IHostBuilder UseSerilog( if (configureLogger == null) throw new ArgumentNullException(nameof(configureLogger)); // This check is eager; replacing the bootstrap logger after calling this method is not supported. +#if !NO_RELOADABLE_LOGGER var reloadable = Log.Logger as ReloadableLogger; var useReload = reloadable != null && !preserveStaticLogger; +#else + const bool useReload = false; +#endif builder.ConfigureServices((context, collection) => { @@ -154,6 +158,7 @@ public static IHostBuilder UseSerilog( collection.AddSingleton(services => { ILogger logger; +#if !NO_RELOADABLE_LOGGER if (useReload) { reloadable!.Reload(cfg => @@ -168,6 +173,7 @@ public static IHostBuilder UseSerilog( logger = reloadable.Freeze(); } else +#endif { var loggerConfiguration = new LoggerConfiguration(); diff --git a/test/Serilog.Extensions.Hosting.Tests/ReloadableLoggerTests.cs b/test/Serilog.Extensions.Hosting.Tests/ReloadableLoggerTests.cs index e14f4aa..cd64435 100644 --- a/test/Serilog.Extensions.Hosting.Tests/ReloadableLoggerTests.cs +++ b/test/Serilog.Extensions.Hosting.Tests/ReloadableLoggerTests.cs @@ -1,4 +1,6 @@ -using Xunit; +#if !NO_RELOADABLE_LOGGER + +using Xunit; namespace Serilog.Extensions.Hosting.Tests { @@ -20,3 +22,5 @@ public void AFrozenLoggerYieldsSerilogLoggers() } } } + +#endif diff --git a/test/Serilog.Extensions.Hosting.Tests/Serilog.Extensions.Hosting.Tests.csproj b/test/Serilog.Extensions.Hosting.Tests/Serilog.Extensions.Hosting.Tests.csproj index 9214cd1..1601189 100644 --- a/test/Serilog.Extensions.Hosting.Tests/Serilog.Extensions.Hosting.Tests.csproj +++ b/test/Serilog.Extensions.Hosting.Tests/Serilog.Extensions.Hosting.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + netcoreapp3.1;net5.0;net4.8 Serilog.Extensions.Hosting.Tests ../../assets/Serilog.snk true @@ -10,6 +10,10 @@ latest + + $(DefineConstants);NO_RELOADABLE_LOGGER + +