Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion uSync.AutoTemplates/TemplateWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ private void CheckFile(string filename)
{
if (_templateFileSystem?.FileExists(filename) is false) return;

_logger.LogInformation("Checking {filename} template", filename);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Checking {filename} template", filename);

var fileAlias = GetAliasFromFileName(filename);

Expand Down
13 changes: 8 additions & 5 deletions uSync.BackOffice/Boot/FirstBootMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ protected override async Task MigrateAsync()

if (_serverRoleAccessor.CurrentServerRole == ServerRole.Subscriber)
{
_logger.LogInformation("This is a Subscriber server in a load balanced setup - uSync only runs on single or schedulingPublisher (main) servers");
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("This is a Subscriber server in a load balanced setup - uSync only runs on single or schedulingPublisher (main) servers");

return;
}

var sw = Stopwatch.StartNew();
var changes = 0;

_logger.LogInformation("Import on First-boot Set - will import {group} handler groups",
_uSyncConfig.Settings.FirstBootGroup);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Import on First-boot Set - will import {group} handler groups", _uSyncConfig.Settings.FirstBootGroup);

// if config service is set to import on first boot then this
// will let uSync do a first boot import
Expand All @@ -95,8 +97,9 @@ protected override async Task MigrateAsync()
};

sw.Stop();
_logger.LogInformation("uSync First boot complete {changes} changes in ({time}ms)",
changes, sw.ElapsedMilliseconds);

if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync First boot complete {changes} changes in ({time}ms)", changes, sw.ElapsedMilliseconds);
}
catch (Exception ex)
{
Expand Down
17 changes: 13 additions & 4 deletions uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,28 @@ protected override void PublishScopedNotifications(IList<INotification> notifica
{
if (notifications.Count == 0) return;

_logger.LogDebug(">> Publishing Notifications [{count}]", notifications.Count);
if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug(">> Publishing Notifications [{count}]", notifications.Count);

var sw = Stopwatch.StartNew();

SetNotificationStates(notifications);

if (_uSyncConfig.Settings.BackgroundNotifications is true && _backgroundTaskQueue != null)
{
_logger.LogDebug("Processing notifications in background queue");
if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("Processing notifications in background queue");

_backgroundTaskQueue.QueueBackgroundWorkItem(
cancellationToken =>
{
using (ExecutionContext.SuppressFlow())
{
Task.Run(() => base.PublishScopedNotifications(notifications), cancellationToken);
_logger.LogDebug("Background Events Processed");

if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("Background Events Processed");

return Task.CompletedTask;
}
});
Expand All @@ -95,7 +102,9 @@ protected override void PublishScopedNotifications(IList<INotification> notifica

}
sw.Stop();
_logger.LogDebug("<< Notifications processed - {elapsed}ms", sw.ElapsedMilliseconds);

if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("<< Notifications processed - {elapsed}ms", sw.ElapsedMilliseconds);

if (sw.ElapsedMilliseconds / notifications.Count > 2000)
_logger.LogWarning("Processing notifications is slow, you should check for custom code running on notification events that may slow this down");
Expand Down
29 changes: 21 additions & 8 deletions uSync.BackOffice/Notifications/uSyncApplicationStartingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,25 @@ public async Task HandleAsync(UmbracoApplicationStartingNotification notificatio
// are not running on a replica.
if (_runtimeState.Level < RuntimeLevel.Run)
{
_logger.LogInformation("Umbraco is in {mode} mode, so uSync will not run this time.", _runtimeState.Level);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Umbraco is in {mode} mode, so uSync will not run this time.", _runtimeState.Level);

return;
}

if (_serverRegistrar.CurrentServerRole == ServerRole.Subscriber)
{
_logger.LogInformation("This is a replicate server in a load balanced setup - uSync will not run {serverRole}", _serverRegistrar.CurrentServerRole);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("This is a replicate server in a load balanced setup - uSync will not run {serverRole}", _serverRegistrar.CurrentServerRole);

return;
}

if (_uSyncConfig.Settings.BackgroundStartup || _uSyncConfig.Settings.ProcessingMode == SyncProcessingMode.Background)
{
_logger.LogInformation("uSync: Running startup in background");
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync: Running startup in background");

_backgroundTaskQueue.QueueBackgroundWorkItem(
cancellationToken =>
{
Expand Down Expand Up @@ -119,15 +125,17 @@ private async Task InituSyncAsync()
Group = _uSyncConfig.Settings.ExportOnSave
};

_logger.LogInformation("uSync: Running export at startup");
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync: Running export at startup");


_uSyncService.StartupExportAsync(_uSyncConfig.GetWorkingFolder(), options).Wait();
}

if (IsImportAtStartupEnabled())
{
_logger.LogInformation("uSync: Running Import at startup {group}", _uSyncConfig.Settings.ImportAtStartup);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync: Running Import at startup {group}", _uSyncConfig.Settings.ImportAtStartup);

var workingFolder = _uSyncConfig.GetWorkingFolder();
var hasStopFile = HasStopFile(workingFolder);
Expand All @@ -144,7 +152,8 @@ private async Task InituSyncAsync()
}
else
{
_logger.LogInformation("Startup Import blocked by {stopFile} file", _uSyncConfig.Settings.StopFile);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Startup Import blocked by {stopFile} file", _uSyncConfig.Settings.StopFile);
}
}
}
Expand All @@ -156,7 +165,9 @@ private async Task InituSyncAsync()
finally
{
sw.Stop();
_logger.LogInformation("uSync: Startup Complete {elapsed}ms", sw.ElapsedMilliseconds);

if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync: Startup Complete {elapsed}ms", sw.ElapsedMilliseconds);
}

}
Expand Down Expand Up @@ -215,7 +226,9 @@ private async Task ProcessOnceFileAsync(string folder)
{
_syncFileService.DeleteFile($"{folder}/{_uSyncConfig.Settings.OnceFile}");
await _syncFileService.SaveFileAsync($"{folder}/{_uSyncConfig.Settings.StopFile}", "uSync Stop file, prevents startup import");
_logger.LogInformation($"{_uSyncConfig.Settings.OnceFile} file replaced by {_uSyncConfig.Settings.StopFile} file");

if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("{onceFile} file replaced by {stopFile} file", _uSyncConfig.Settings.OnceFile, _uSyncConfig.Settings.StopFile);
}
}

Expand Down
14 changes: 9 additions & 5 deletions uSync.BackOffice/Services/SyncActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ private string MakeValidImportFolder(string folder)
/// <inheritdoc/>
public async Task StartProcessAsync(SyncStartActionRequest request)
{
_logger.LogInformation("[uSync {version}] {user} Starting {action} process",
uSync.Version.ToString(3), request.Username, request.HandlerAction);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("[uSync {version}] {user} Starting {action} process", uSync.Version.ToString(3), request.Username, request.HandlerAction);

_timer = Stopwatch.StartNew();
await _uSyncService.StartBulkProcessAsync(request.HandlerAction);

Expand All @@ -211,9 +212,12 @@ public async Task<SyncActionResult> FinishProcessAsync(SyncFinalActionRequest re
_timer?.Stop();
var elapsed = _timer?.ElapsedMilliseconds ?? 0;

_logger.LogInformation("[uSync {version}] {user} finished {action} process ({changes}/{count} changes) in ({time:#,#}ms)",
uSync.Version.ToString(3), request.Username, request.HandlerAction,
request.Actions.CountChanges(), request.Actions.Count(), elapsed);
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("[uSync {version}] {user} finished {action} process ({changes}/{count} changes) in ({time:#,#}ms)",
uSync.Version.ToString(3), request.Username, request.HandlerAction,
request.Actions.CountChanges(), request.Actions.Count(), elapsed);
}

request.Callbacks?.Update?.Invoke($"{request.HandlerAction} completed ({elapsed:#,#}ms)", 1, 1);

Expand Down
7 changes: 5 additions & 2 deletions uSync.BackOffice/Services/SyncFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ public async Task<XElement> LoadXElementAsync(string file)
/// <inheritdoc/>
public async Task SaveFileAsync(string filename, Stream stream)
{
_logger.LogDebug("Saving File: {file}", filename);
if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("Saving File: {file}", filename);

using (Stream fileStream = OpenWrite(filename))
{
Expand All @@ -227,7 +228,9 @@ public async Task SaveFileAsync(string filename, Stream stream)
public async Task SaveFileAsync(string filename, string content)
{
var localFile = GetAbsPath(filename);
_logger.LogDebug("Saving File: {local} [{length}]", localFile, content.Length);

if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("Saving File: {local} [{length}]", localFile, content.Length);

using (Stream stream = OpenWrite(localFile))
{
Expand Down
34 changes: 22 additions & 12 deletions uSync.BackOffice/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public async Task<IEnumerable<uSyncAction>> StartupImportAsync(string[] folders,

if (_lastStartupRun.HasValue && _lastStartupRun.Value == runHash)
{
_logger.LogInformation("uSync: Skipping [duplicate] startup import has already ran with these parameters");
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("uSync: Skipping [duplicate] startup import has already ran with these parameters");

return [];
}

Expand Down Expand Up @@ -212,11 +214,14 @@ public async Task<IEnumerable<uSyncAction>> ImportAsync(string[] folders, bool f
// fire complete
await _mutexService.FireBulkCompleteAsync(new uSyncImportCompletedNotification(actions, handlerOptions.Group));

_logger.LogInformation("uSync Import: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms",
handlers.Count(),
actions.Count,
actions.CountChanges(),
sw.ElapsedMilliseconds);
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("uSync Import: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms",
handlers.Count(),
actions.Count,
actions.CountChanges(),
sw.ElapsedMilliseconds);
}

if (actions.ContainsErrors())
_logger.LogWarning("uSync Import: Errors detected in import : {count}", actions.CountErrors());
Expand Down Expand Up @@ -419,10 +424,13 @@ public async Task<IEnumerable<uSyncAction>> ExportAsync(string folder, IEnumerab

sw.Stop();

_logger.LogInformation("uSync Export: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms",
handlers.Count(), actions.Count,
actions.CountChanges(),
sw.ElapsedMilliseconds);
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("uSync Export: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms",
handlers.Count(), actions.Count,
actions.CountChanges(),
sw.ElapsedMilliseconds);
}

callbacks?.Update?.Invoke($"Processed {actions.Count} items in {sw.ElapsedMilliseconds}ms", 1, 1);

Expand All @@ -439,7 +447,8 @@ private void USyncTriggers_DoImport(uSyncTriggerArgs e)
{
if (e.EntityTypes != null && !string.IsNullOrWhiteSpace(e.Folder))
{
_logger.LogInformation("Import Triggered by downlevel change {folder}", e.Folder);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Import Triggered by downlevel change {folder}", e.Folder);

var handlers = _handlerFactory
.GetValidHandlersByEntityType(e.EntityTypes, e.HandlerOptions);
Expand All @@ -464,7 +473,8 @@ private void USyncTriggers_DoExport(uSyncTriggerArgs e)
{
if (e.EntityTypes != null && !string.IsNullOrWhiteSpace(e.Folder))
{
_logger.LogInformation("Export Triggered by downlevel change {folder}", e.Folder);
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("Export Triggered by downlevel change {folder}", e.Folder);

var handlers = _handlerFactory
.GetValidHandlersByEntityType(e.EntityTypes, e.HandlerOptions);
Expand Down
4 changes: 3 additions & 1 deletion uSync.BackOffice/Services/SyncService_Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public async Task<IEnumerable<uSyncAction>> ImportPartialAsync(IList<OrderedNode
}
finally
{
_logger.LogDebug("Imported {count} items", actions.Count);
if (_logger.IsEnabled(LogLevel.Debug))
_logger.LogDebug("Imported {count} items", actions.Count);

scope?.Complete();
}

Expand Down
20 changes: 15 additions & 5 deletions uSync.BackOffice/SyncHandlers/Handlers/ContentHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ private bool ImportPaths(XElement node, HandlerSettings config)
var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
if (!string.IsNullOrWhiteSpace(path) && !include.Any(x => path.InvariantStartsWith(x)))
{
logger.LogDebug("Not processing item, {alias} path {path} not in include path", node.GetAlias(), path);
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Not processing item, {alias} path {path} not in include path", node.GetAlias(), path);

return false;
}
}
Expand All @@ -131,7 +133,9 @@ private bool ImportPaths(XElement node, HandlerSettings config)
var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
if (!string.IsNullOrWhiteSpace(path) && exclude.Any(x => path.InvariantStartsWith(x)))
{
logger.LogDebug("Not processing item, {alias} path {path} is excluded", node.GetAlias(), path);
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Not processing item, {alias} path {path} is excluded", node.GetAlias(), path);

return false;
}
}
Expand All @@ -148,14 +152,18 @@ private bool ByDocTypeConfigCheck(XElement node, HandlerSettings config)

if (includeDocTypes.Length > 0 && !includeDocTypes.InvariantContains(doctype))
{
logger.LogDebug("Not processing {alias} as it in not in the Included by ContentType list {contentType}", node.GetAlias(), doctype);
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Not processing {alias} as it in not in the Included by ContentType list {contentType}", node.GetAlias(), doctype);

return false;
}

var excludeDocTypes = config.GetSetting("ExcludeContentTypes", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
if (excludeDocTypes.Length > 0 && excludeDocTypes.InvariantContains(doctype))
{
logger.LogDebug("Not processing {alias} as it is excluded by ContentType {contentType}", node.GetAlias(), doctype);
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Not processing {alias} as it is excluded by ContentType {contentType}", node.GetAlias(), doctype);

return false;
}

Expand Down Expand Up @@ -231,7 +239,9 @@ protected override async Task CleanUpAsync(TObject item, string newFile, string
bool quickCleanup = this.DefaultConfig.GetSetting("QuickCleanup", false);
if (quickCleanup)
{
logger.LogDebug("Quick cleanup is on, so not looking in all config files");
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Quick cleanup is on, so not looking in all config files");

return;
}

Expand Down
8 changes: 6 additions & 2 deletions uSync.BackOffice/SyncHandlers/Handlers/LanguageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ protected override async Task CleanUpAsync(ILanguage item, string newFile, strin
// not the file we just saved, but matching IsoCode, we remove it.
if (node.Element("IsoCode").ValueOrDefault(string.Empty) == item.IsoCode)
{
logger.LogDebug("Found Matching Lang File, cleaning");
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Found Matching Lang File, cleaning");

var attempt = await serializer.SerializeEmptyAsync(item, SyncActionType.Rename, node.GetAlias());
if (attempt.Success && attempt.Item is not null)
{
Expand All @@ -152,7 +154,9 @@ protected override async Task CleanUpAsync(ILanguage item, string newFile, strin
if (!installedLanguages.InvariantContains(IsoCode))
{
// language is no longer installed, make the file empty.
logger.LogDebug("Language in file is not on the site, cleaning");
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Language in file is not on the site, cleaning");

var attempt = await serializer.SerializeEmptyAsync(item, SyncActionType.Delete, node.GetAlias());
if (attempt.Success && attempt.Item is not null)
{
Expand Down
Loading
Loading