From fe1df8d4ea209e89f3bd4f79c1ffed533f235363 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 13:47:58 +0100 Subject: [PATCH 01/10] Amend breaking change --- .../HostedServices/RecurringHostedServiceBase.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 18fe9fc47f..3ac04a73c6 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -4,8 +4,10 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Infrastructure.HostedServices { @@ -41,6 +43,13 @@ namespace Umbraco.Cms.Infrastructure.HostedServices _delay = delay; } + // Scheduled for removal in V11 + [Obsolete("Please use constructor that takes an ILogger instead")] + protected RecurringHostedServiceBase(TimeSpan period, TimeSpan delay) + : this(StaticServiceProvider.Instance.GetRequiredService(), period, delay) + { + } + /// public Task StartAsync(CancellationToken cancellationToken) { From 5a613bacf06fa4b5b1bfd3ecb0ab4e4ed4e7a9dc Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 14:09:47 +0100 Subject: [PATCH 02/10] Amend breaking change v2 --- .../RecurringHostedServiceBase.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 3ac04a73c6..14f779d079 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices /// protected static readonly TimeSpan DefaultDelay = TimeSpan.FromMinutes(3); - private readonly ILogger _logger; + private readonly ILogger _logger; private TimeSpan _period; private readonly TimeSpan _delay; private Timer _timer; @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices /// Logger. /// Timespan representing how often the task should recur. /// Timespan representing the initial delay after application start-up before the first run of the task occurs. - protected RecurringHostedServiceBase(ILogger logger, TimeSpan period, TimeSpan delay) + protected RecurringHostedServiceBase(ILogger logger, TimeSpan period, TimeSpan delay) { _logger = logger; _period = period; @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices // Scheduled for removal in V11 [Obsolete("Please use constructor that takes an ILogger instead")] protected RecurringHostedServiceBase(TimeSpan period, TimeSpan delay) - : this(StaticServiceProvider.Instance.GetRequiredService(), period, delay) + : this(StaticServiceProvider.Instance.GetRequiredService().CreateLogger(), period, delay) { } @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices } catch (Exception ex) { - _logger.LogError(ex, "Unhandled exception in recurring hosted service {serviceName}.", GetType().Name); + _logger.LogError(ex, "Unhandled exception in recurring hosted service {serviceName}."); } finally { @@ -120,4 +120,14 @@ namespace Umbraco.Cms.Infrastructure.HostedServices GC.SuppressFinalize(this); } } + + public class RecurringHostedServiceBaseImpl : RecurringHostedServiceBase + { + + public RecurringHostedServiceBaseImpl(TimeSpan period, TimeSpan delay) : base(period, delay) + { + } + + public override Task PerformExecuteAsync(object state) => Task.CompletedTask; + } } From b55ee70fe84dcf279c2d05a102dd36f34dbd5ea0 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 14:14:54 +0100 Subject: [PATCH 03/10] Switched from service location to StaticAplicationLogging --- .../HostedServices/RecurringHostedServiceBase.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 14f779d079..e78374205c 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -4,10 +4,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Umbraco.Cms.Web.Common.DependencyInjection; +using Umbraco.Cms.Core; namespace Umbraco.Cms.Infrastructure.HostedServices { @@ -46,7 +45,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices // Scheduled for removal in V11 [Obsolete("Please use constructor that takes an ILogger instead")] protected RecurringHostedServiceBase(TimeSpan period, TimeSpan delay) - : this(StaticServiceProvider.Instance.GetRequiredService().CreateLogger(), period, delay) + : this(StaticApplicationLogging.CreateLogger(), period, delay) { } From cca29bf723c622947f1c113782fee7fbbda3f606 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 14:16:46 +0100 Subject: [PATCH 04/10] Don't commit test classes. --- .../HostedServices/RecurringHostedServiceBase.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index e78374205c..a4ab41fd7a 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -119,14 +119,4 @@ namespace Umbraco.Cms.Infrastructure.HostedServices GC.SuppressFinalize(this); } } - - public class RecurringHostedServiceBaseImpl : RecurringHostedServiceBase - { - - public RecurringHostedServiceBaseImpl(TimeSpan period, TimeSpan delay) : base(period, delay) - { - } - - public override Task PerformExecuteAsync(object state) => Task.CompletedTask; - } } From fd701068ae4bfa7a80db4e3fb1e465551eac09d2 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Tue, 22 Mar 2022 14:18:12 +0100 Subject: [PATCH 05/10] Update src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs Co-authored-by: Paul Johnson --- .../HostedServices/RecurringHostedServiceBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index a4ab41fd7a..2b63f45734 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices /// protected static readonly TimeSpan DefaultDelay = TimeSpan.FromMinutes(3); - private readonly ILogger _logger; + private readonly ILogger _logger; private TimeSpan _period; private readonly TimeSpan _delay; private Timer _timer; From c6bfc61909f81351d950d1439468bf3a1a7ed3b1 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Tue, 22 Mar 2022 14:21:53 +0100 Subject: [PATCH 06/10] Update src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs Co-authored-by: Paul Johnson --- .../HostedServices/RecurringHostedServiceBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 2b63f45734..32e2ab188d 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices /// Logger. /// Timespan representing how often the task should recur. /// Timespan representing the initial delay after application start-up before the first run of the task occurs. - protected RecurringHostedServiceBase(ILogger logger, TimeSpan period, TimeSpan delay) + protected RecurringHostedServiceBase(ILogger logger, TimeSpan period, TimeSpan delay) { _logger = logger; _period = period; From 3f7f2797a6cd0ef764bea5c3f5f87238d8fff0ab Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 14:52:39 +0100 Subject: [PATCH 07/10] Add CreateLogger method so we still can get types using the legacy ctor --- src/Umbraco.Core/StaticApplicationLogging.cs | 6 ++++++ .../HostedServices/RecurringHostedServiceBase.cs | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/StaticApplicationLogging.cs b/src/Umbraco.Core/StaticApplicationLogging.cs index e216011014..0f32075144 100644 --- a/src/Umbraco.Core/StaticApplicationLogging.cs +++ b/src/Umbraco.Core/StaticApplicationLogging.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -18,5 +19,10 @@ namespace Umbraco.Cms.Core { return _loggerFactory?.CreateLogger() ?? NullLoggerFactory.Instance.CreateLogger(); } + + public static ILogger CreateLogger(Type type) + { + return _loggerFactory?.CreateLogger(type) ?? NullLoggerFactory.Instance.CreateLogger(type); + } } } diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 32e2ab188d..7686c357a4 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -45,8 +45,10 @@ namespace Umbraco.Cms.Infrastructure.HostedServices // Scheduled for removal in V11 [Obsolete("Please use constructor that takes an ILogger instead")] protected RecurringHostedServiceBase(TimeSpan period, TimeSpan delay) - : this(StaticApplicationLogging.CreateLogger(), period, delay) { + _period = period; + _delay = delay; + _logger = StaticApplicationLogging.CreateLogger(GetType()); } /// From 10ae51273166978f410e49590091ad4727da840b Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 15:12:51 +0100 Subject: [PATCH 08/10] Use ILoggerFactory instead of StaticApplicationLogging --- src/Umbraco.Core/StaticApplicationLogging.cs | 5 ----- .../HostedServices/RecurringHostedServiceBase.cs | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/StaticApplicationLogging.cs b/src/Umbraco.Core/StaticApplicationLogging.cs index 0f32075144..73078b0f42 100644 --- a/src/Umbraco.Core/StaticApplicationLogging.cs +++ b/src/Umbraco.Core/StaticApplicationLogging.cs @@ -19,10 +19,5 @@ namespace Umbraco.Cms.Core { return _loggerFactory?.CreateLogger() ?? NullLoggerFactory.Instance.CreateLogger(); } - - public static ILogger CreateLogger(Type type) - { - return _loggerFactory?.CreateLogger(type) ?? NullLoggerFactory.Instance.CreateLogger(type); - } } } diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index 7686c357a4..d906738430 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -4,9 +4,10 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core; +using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Infrastructure.HostedServices { @@ -48,7 +49,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices { _period = period; _delay = delay; - _logger = StaticApplicationLogging.CreateLogger(GetType()); + _logger = StaticServiceProvider.Instance.GetRequiredService().CreateLogger(GetType()); } /// From 496e281f2a84bb55c6c638038986c79cf38e7b24 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Tue, 22 Mar 2022 15:34:27 +0100 Subject: [PATCH 09/10] Add back service name --- .../HostedServices/RecurringHostedServiceBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs index d906738430..c1c7cdf3cf 100644 --- a/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs +++ b/src/Umbraco.Infrastructure/HostedServices/RecurringHostedServiceBase.cs @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices } catch (Exception ex) { - _logger.LogError(ex, "Unhandled exception in recurring hosted service {serviceName}."); + _logger.LogError(ex, "Unhandled exception in recurring hosted service."); } finally { From 7114c564da5f0b753e2f42d01a4a1cf4e08d78fb Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Wed, 23 Mar 2022 08:27:48 +0100 Subject: [PATCH 10/10] Amend unintentional change --- .../HostedServices/ContentVersionCleanup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs b/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs index 8c9f3223f0..d037c91d86 100644 --- a/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs +++ b/src/Umbraco.Infrastructure/HostedServices/ContentVersionCleanup.cs @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices IContentVersionService service, IMainDom mainDom, IServerRoleAccessor serverRoleAccessor) - : base(logger, TimeSpan.FromHours(1), TimeSpan.FromMinutes(1)) + : base(logger, TimeSpan.FromHours(1), TimeSpan.FromMinutes(3)) { _runtimeState = runtimeState; _logger = logger;