Fix obsolete constructor in RecurringHostedServiceBase (#12172)

* Use NullLogger in obsoleted constructor

* Create missing logger during execution instead

(cherry picked from commit d0823d4236)
This commit is contained in:
Ronald Barendse
2022-03-24 11:34:29 +01:00
committed by Paul Johnson
parent 4fffb9f7a7
commit 037580b305
5 changed files with 18 additions and 25 deletions

View File

@@ -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,11 +45,8 @@ 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)
{
_period = period;
_delay = delay;
_logger = StaticServiceProvider.Instance.GetRequiredService<ILoggerFactory>().CreateLogger(GetType());
}
: this(null, period, delay)
{ }
/// <inheritdoc/>
public Task StartAsync(CancellationToken cancellationToken)
@@ -82,7 +78,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
}
catch (Exception ex)
{
_logger.LogError(ex, "Unhandled exception in recurring hosted service.");
ILogger logger = _logger ?? StaticApplicationLogging.CreateLogger(GetType());
logger.LogError(ex, "Unhandled exception in recurring hosted service.");
}
finally
{
@@ -108,7 +105,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
{
if (disposing)
{
_timer?.Dispose();
_timer?.Dispose();
}
_disposedValue = true;