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:
committed by
Paul Johnson
parent
4fffb9f7a7
commit
037580b305
@@ -24,7 +24,7 @@
|
||||
"version": {
|
||||
"type": "parameter",
|
||||
"datatype": "string",
|
||||
"defaultValue": "9.4.0",
|
||||
"defaultValue": "9.4.1",
|
||||
"description": "The version of Umbraco to load using NuGet",
|
||||
"replaces": "UMBRACO_VERSION_FROM_TEMPLATE"
|
||||
},
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
"version": {
|
||||
"type": "parameter",
|
||||
"datatype": "string",
|
||||
"defaultValue": "9.4.0",
|
||||
"defaultValue": "9.4.1",
|
||||
"description": "The version of Umbraco to load using NuGet",
|
||||
"replaces": "UMBRACO_VERSION_FROM_TEMPLATE"
|
||||
},
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<Project>
|
||||
<Project>
|
||||
<!-- Enable multi-level merging -->
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>9.4.0</Version>
|
||||
<AssemblyVersion>9.4.0</AssemblyVersion>
|
||||
<InformationalVersion>9.4.0</InformationalVersion>
|
||||
<FileVersion>9.4.0</FileVersion>
|
||||
<Version>9.4.1</Version>
|
||||
<AssemblyVersion>9.4.1</AssemblyVersion>
|
||||
<InformationalVersion>9.4.1</InformationalVersion>
|
||||
<FileVersion>9.4.1</FileVersion>
|
||||
<LangVersion Condition="'$(LangVersion)' == ''">9.0</LangVersion>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Company>Umbraco CMS</Company>
|
||||
|
||||
@@ -6,18 +6,14 @@ namespace Umbraco.Cms.Core
|
||||
{
|
||||
public static class StaticApplicationLogging
|
||||
{
|
||||
private static ILoggerFactory _loggerFactory;
|
||||
private static ILoggerFactory s_loggerFactory;
|
||||
|
||||
public static void Initialize(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_loggerFactory = loggerFactory;
|
||||
}
|
||||
public static void Initialize(ILoggerFactory loggerFactory) => s_loggerFactory = loggerFactory;
|
||||
|
||||
public static ILogger<object> Logger => CreateLogger<object>();
|
||||
|
||||
public static ILogger<T> CreateLogger<T>()
|
||||
{
|
||||
return _loggerFactory?.CreateLogger<T>() ?? NullLoggerFactory.Instance.CreateLogger<T>();
|
||||
}
|
||||
public static ILogger<T> CreateLogger<T>() => s_loggerFactory?.CreateLogger<T>() ?? NullLoggerFactory.Instance.CreateLogger<T>();
|
||||
|
||||
public static ILogger CreateLogger(Type type) => s_loggerFactory?.CreateLogger(type) ?? NullLogger.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user