Add more logging fixes
This commit is contained in:
@@ -12,22 +12,24 @@ namespace Umbraco.Core.Composing
|
||||
{
|
||||
private const int LogThresholdMilliseconds = 100;
|
||||
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly ILogger<ComponentCollection> _logger;
|
||||
|
||||
public ComponentCollection(IEnumerable<IComponent> items, IProfilingLogger logger)
|
||||
public ComponentCollection(IEnumerable<IComponent> items, IProfilingLogger profilingLogger, ILogger<ComponentCollection> logger)
|
||||
: base(items)
|
||||
{
|
||||
_profilingLogger = profilingLogger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
using (_logger.DebugDuration<ComponentCollection>($"Initializing. (log components when >{LogThresholdMilliseconds}ms)", "Initialized."))
|
||||
using (_profilingLogger.DebugDuration<ComponentCollection>($"Initializing. (log components when >{LogThresholdMilliseconds}ms)", "Initialized."))
|
||||
{
|
||||
foreach (var component in this)
|
||||
{
|
||||
var componentType = component.GetType();
|
||||
using (_logger.DebugDuration<ComponentCollection>($"Initializing {componentType.FullName}.", $"Initialized {componentType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds))
|
||||
using (_profilingLogger.DebugDuration<ComponentCollection>($"Initializing {componentType.FullName}.", $"Initialized {componentType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds))
|
||||
{
|
||||
component.Initialize();
|
||||
}
|
||||
@@ -37,12 +39,12 @@ namespace Umbraco.Core.Composing
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
using (_logger.DebugDuration<ComponentCollection>($"Terminating. (log components when >{LogThresholdMilliseconds}ms)", "Terminated."))
|
||||
using (_profilingLogger.DebugDuration<ComponentCollection>($"Terminating. (log components when >{LogThresholdMilliseconds}ms)", "Terminated."))
|
||||
{
|
||||
foreach (var component in this.Reverse()) // terminate components in reverse order
|
||||
{
|
||||
var componentType = component.GetType();
|
||||
using (_logger.DebugDuration<ComponentCollection>($"Terminating {componentType.FullName}.", $"Terminated {componentType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds))
|
||||
using (_profilingLogger.DebugDuration<ComponentCollection>($"Terminating {componentType.FullName}.", $"Terminated {componentType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -51,7 +53,7 @@ namespace Umbraco.Core.Composing
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError<ComponentCollection>(ex, "Error while terminating component {ComponentType}.", componentType.FullName);
|
||||
_logger.LogError(ex, "Error while terminating component {ComponentType}.", componentType.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,20 @@ namespace Umbraco.Web.Scheduling
|
||||
private readonly IRequestAccessor _requestAccessor;
|
||||
private readonly IMainDom _mainDom;
|
||||
private readonly IKeepAliveSettings _keepAliveSettings;
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly ILogger<KeepAlive> _logger;
|
||||
private readonly ProfilingLogger _profilingLogger;
|
||||
private readonly IServerRegistrar _serverRegistrar;
|
||||
private static HttpClient _httpClient;
|
||||
|
||||
public KeepAlive(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds,
|
||||
IRequestAccessor requestAccessor, IMainDom mainDom, IKeepAliveSettings keepAliveSettings, IProfilingLogger logger, IServerRegistrar serverRegistrar)
|
||||
IRequestAccessor requestAccessor, IMainDom mainDom, IKeepAliveSettings keepAliveSettings, ILogger<KeepAlive> logger, ProfilingLogger profilingLogger, IServerRegistrar serverRegistrar)
|
||||
: base(runner, delayMilliseconds, periodMilliseconds)
|
||||
{
|
||||
_requestAccessor = requestAccessor;
|
||||
_mainDom = mainDom;
|
||||
_keepAliveSettings = keepAliveSettings;
|
||||
_logger = logger;
|
||||
_profilingLogger = profilingLogger;
|
||||
_serverRegistrar = serverRegistrar;
|
||||
if (_httpClient == null)
|
||||
_httpClient = new HttpClient();
|
||||
@@ -37,21 +39,21 @@ namespace Umbraco.Web.Scheduling
|
||||
switch (_serverRegistrar.GetCurrentServerRole())
|
||||
{
|
||||
case ServerRole.Replica:
|
||||
_logger.Debug<KeepAlive>("Does not run on replica servers.");
|
||||
_logger.LogDebug("Does not run on replica servers.");
|
||||
return true; // role may change!
|
||||
case ServerRole.Unknown:
|
||||
_logger.Debug<KeepAlive>("Does not run on servers with unknown role.");
|
||||
_logger.LogDebug("Does not run on servers with unknown role.");
|
||||
return true; // role may change!
|
||||
}
|
||||
|
||||
// ensure we do not run if not main domain, but do NOT lock it
|
||||
if (_mainDom.IsMainDom == false)
|
||||
{
|
||||
_logger.Debug<KeepAlive>("Does not run if not MainDom.");
|
||||
_logger.LogDebug("Does not run if not MainDom.");
|
||||
return false; // do NOT repeat, going down
|
||||
}
|
||||
|
||||
using (_logger.DebugDuration<KeepAlive>("Keep alive executing", "Keep alive complete"))
|
||||
using (_profilingLogger.DebugDuration<KeepAlive>("Keep alive executing", "Keep alive complete"))
|
||||
{
|
||||
var keepAlivePingUrl = _keepAliveSettings.KeepAlivePingUrl;
|
||||
try
|
||||
@@ -61,7 +63,7 @@ namespace Umbraco.Web.Scheduling
|
||||
var umbracoAppUrl = _requestAccessor.GetApplicationUrl().ToString();
|
||||
if (umbracoAppUrl.IsNullOrWhiteSpace())
|
||||
{
|
||||
_logger.LogWarning<KeepAlive>("No umbracoApplicationUrl for service (yet), skip.");
|
||||
_logger.LogWarning("No umbracoApplicationUrl for service (yet), skip.");
|
||||
return true; // repeat
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ namespace Umbraco.Web.Scheduling
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError<KeepAlive>(ex, "Keep alive failed (at '{keepAlivePingUrl}').", keepAlivePingUrl);
|
||||
_logger.LogError(ex, "Keep alive failed (at '{keepAlivePingUrl}').", keepAlivePingUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,12 @@ namespace Umbraco.Web.Scheduling
|
||||
private readonly DirectoryInfo[] _tempFolders;
|
||||
private readonly TimeSpan _age;
|
||||
private readonly IMainDom _mainDom;
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly ILogger<TempFileCleanup> _logger;
|
||||
|
||||
public TempFileCleanup(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds,
|
||||
IEnumerable<DirectoryInfo> tempFolders, TimeSpan age,
|
||||
IMainDom mainDom, IProfilingLogger logger)
|
||||
IMainDom mainDom, IProfilingLogger profilingLogger, ILogger<TempFileCleanup> logger)
|
||||
: base(runner, delayMilliseconds, periodMilliseconds)
|
||||
{
|
||||
//SystemDirectories.TempFileUploads
|
||||
@@ -27,6 +28,7 @@ namespace Umbraco.Web.Scheduling
|
||||
_tempFolders = tempFolders.ToArray();
|
||||
_age = age;
|
||||
_mainDom = mainDom;
|
||||
_profilingLogger = profilingLogger;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ namespace Umbraco.Web.Scheduling
|
||||
// ensure we do not run if not main domain
|
||||
if (_mainDom.IsMainDom == false)
|
||||
{
|
||||
_logger.Debug<TempFileCleanup>("Does not run if not MainDom.");
|
||||
_logger.LogDebug("Does not run if not MainDom.");
|
||||
return false; // do NOT repeat, going down
|
||||
}
|
||||
|
||||
@@ -50,7 +52,7 @@ namespace Umbraco.Web.Scheduling
|
||||
dir.Refresh(); //in case it's changed during runtime
|
||||
if (!dir.Exists)
|
||||
{
|
||||
_logger.Debug<TempFileCleanup>("The cleanup folder doesn't exist {Folder}", dir.FullName);
|
||||
_logger.LogDebug("The cleanup folder doesn't exist {Folder}", dir.FullName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +68,7 @@ namespace Umbraco.Web.Scheduling
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError<TempFileCleanup>(ex, "Could not delete temp file {FileName}", file.FullName);
|
||||
_logger.LogError(ex, "Could not delete temp file {FileName}", file.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace Umbraco.Examine
|
||||
/// </summary>
|
||||
public class LuceneIndexDiagnosticsFactory : IndexDiagnosticsFactory
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger<LuceneIndexDiagnostics> _logger;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public LuceneIndexDiagnosticsFactory(ILogger logger, IHostingEnvironment hostingEnvironment)
|
||||
public LuceneIndexDiagnosticsFactory(ILogger<LuceneIndexDiagnostics> logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_logger = logger;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
|
||||
Reference in New Issue
Block a user