From b3df47c9cc567f8155ffce9d22fa5619a63c97d7 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 24 Sep 2019 22:40:32 +0200 Subject: [PATCH] ILoggerFactory is obsolete in .NET Core 3. Instead use ILoggingBuilder.AddNLog (#342) * ILoggerFactory is obsolete in NetCore3. Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog() * Version 1.6.0 * Updated to NLog 4.6.7 * Update CHANGELOG.MD --- CHANGELOG.MD | 4 ++++ build.ps1 | 2 +- .../Extensions/ConfigureExtensions.cs | 9 +++++++++ .../NLog.Extensions.Logging.csproj | 6 ++++-- .../Extensions/ConfigureExtensionsTests.cs | 2 ++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 884fcb82..1266f9ab 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -2,6 +2,10 @@ Date format: (year/month/day) +### v1.6.0 (2019/09/24) +- [#342](https://github.com/NLog/NLog.Extensions.Logging/pull/342) ILoggerFactory is obsolete in .NET Core 3. Instead use ILoggingBuilder.AddNLog +- [#333](https://github.com/NLog/NLog.Extensions.Logging/pull/333) + [#334](https://github.com/NLog/NLog.Extensions.Logging/pull/334) Minor optimization in parsing of LogEvent property-names + ### v1.5.4 (2019/09/06) - [#325](https://github.com/NLog/NLog.Extensions.Logging/pull/325) Fix dispose for AddNLog (on ILoggingBuilder) and no double logging when also using UseNLog (@snakefoot) diff --git a/build.ps1 b/build.ps1 index 26511f11..d9dbe2c8 100644 --- a/build.ps1 +++ b/build.ps1 @@ -2,7 +2,7 @@ # creates NuGet package at \artifacts dotnet --version -$versionPrefix = "1.5.4" +$versionPrefix = "1.6.0" $versionSuffix = "" $versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER} $versionProduct = $versionPrefix; diff --git a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs index 2c915e15..a42e0165 100644 --- a/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs +++ b/src/NLog.Extensions.Logging/Extensions/ConfigureExtensions.cs @@ -22,6 +22,9 @@ public static class ConfigureExtensions /// /// /// ILoggerFactory for chaining +#if !NETCORE1_0 + [Obsolete("Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog()")] +#endif public static ILoggerFactory AddNLog(this ILoggerFactory factory) { return factory.AddNLog(NLogProviderOptions.Default); @@ -33,6 +36,9 @@ public static ILoggerFactory AddNLog(this ILoggerFactory factory) /// /// NLog options /// ILoggerFactory for chaining +#if !NETCORE1_0 + [Obsolete("Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog()")] +#endif public static ILoggerFactory AddNLog(this ILoggerFactory factory, NLogProviderOptions options) { factory.AddProvider(new NLogLoggerProvider(options)); @@ -45,6 +51,9 @@ public static ILoggerFactory AddNLog(this ILoggerFactory factory, NLogProviderOp /// /// /// ILoggerFactory for chaining +#if !NETCORE1_0 + [Obsolete("Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog()")] +#endif public static ILoggerFactory AddNLog(this ILoggerFactory factory, IConfiguration configuration) { var provider = CreateNLogProvider(configuration); diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index 0b81f2da..b28559d5 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -18,7 +18,9 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.W NLog;Microsoft.Extensions.Logging;log;logging;logfiles;netcore -- Fix dispose for AddNLog (on ILoggingBuilder) and no double logging when also using UseNLog (@snakefoot) +- Marked ILoggerFactory extension methods as obsolete, since obsolete in NetCore3 +- Minor optimization in parsing of LogEvent property-names +- Updated NLog dependency Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD @@ -58,7 +60,7 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN $(DefineConstants);NETSTANDARD - + diff --git a/test/NLog.Extensions.Logging.Tests/Extensions/ConfigureExtensionsTests.cs b/test/NLog.Extensions.Logging.Tests/Extensions/ConfigureExtensionsTests.cs index 4c388752..39a2b8f9 100644 --- a/test/NLog.Extensions.Logging.Tests/Extensions/ConfigureExtensionsTests.cs +++ b/test/NLog.Extensions.Logging.Tests/Extensions/ConfigureExtensionsTests.cs @@ -12,6 +12,7 @@ namespace NLog.Extensions.Logging.Tests.Extensions public class ConfigureExtensionsTests { [Fact] + [Obsolete("Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog()")] public void AddNLog_LoggerFactory_LogInfo_ShouldLogToNLog() { // Arrange @@ -32,6 +33,7 @@ public void AddNLog_LoggerFactory_LogInfo_ShouldLogToNLog() [InlineData("EventId", "eventId2")] [InlineData("EventId_Name", "eventId2")] [InlineData("EventId_Id", "2")] + [Obsolete("Instead use ILoggingBuilder.AddNLog() or IHostBuilder.UseNLog()")] public void AddNLog_LoggerFactory_LogInfoWithEventId_ShouldLogToNLogWithEventId(string eventPropery, string expectedEventInLog) { // Arrange