From 47c865160977f9085dd0facad301835df908ce30 Mon Sep 17 00:00:00 2001 From: Warren Date: Thu, 16 Aug 2018 12:00:12 +0100 Subject: [PATCH] Update more logging messages to use templates as opposed to string formats that were using the LoggerExtensions --- .../Configuration/Grid/GridEditorsConfig.cs | 6 ++++-- src/Umbraco.Core/IO/MediaFileSystem.cs | 2 +- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 10 ++++----- src/Umbraco.Core/Logging/LoggerExtensions.cs | 1 - src/Umbraco.Core/Manifest/ManifestParser.cs | 2 +- src/Umbraco.Core/Manifest/ManifestWatcher.cs | 2 +- .../Install/DatabaseSchemaCreator.cs | 2 +- src/Umbraco.Core/Models/MediaExtensions.cs | 2 +- src/Umbraco.Core/Models/Member.cs | 21 ++++++++++++++----- .../Packaging/PackageBinaryInspector.cs | 4 ++-- .../Implement/ContentRepositoryBase.cs | 5 ++--- .../Implement/ContentTypeRepository.cs | 5 ++--- .../Implement/ContentTypeRepositoryBase.cs | 21 ++++++++++++------- .../Persistence/UmbracoDatabase.cs | 6 +++--- .../ValueConverters/GridValueConverter.cs | 2 +- .../ImageCropperValueConverter.cs | 2 +- .../ValueConverters/JsonValueConverter.cs | 2 +- .../Services/Implement/ContentService.cs | 10 ++++----- .../LocalizedTextServiceFileSources.cs | 2 +- .../Services/Implement/MediaService.cs | 2 +- .../Services/Implement/MemberService.cs | 2 +- .../Services/Implement/PackagingService.cs | 13 +++++++----- .../Sync/DatabaseServerMessenger.cs | 11 ++++++++-- src/Umbraco.Core/UmbracoApplicationBase.cs | 13 ++++++------ 24 files changed, 88 insertions(+), 60 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index a0ca2da4ff..e7e20e157b 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -40,13 +40,15 @@ namespace Umbraco.Core.Configuration.Grid var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js"); if (File.Exists(gridConfig)) { + var sourceString = File.ReadAllText(gridConfig); + try { - editors.AddRange(parser.ParseGridEditors(File.ReadAllText(gridConfig))); + editors.AddRange(parser.ParseGridEditors(sourceString)); } catch (Exception ex) { - _logger.Error("Could not parse the contents of grid.editors.config.js into a JSON array", ex); + _logger.Error("Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", ex, sourceString); } } diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index 9453678a31..b9ee8337f6 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -111,7 +111,7 @@ namespace Umbraco.Core.IO } catch (Exception e) { - Logger.Error("Failed to delete attached file \"" + file + "\".", e); + Logger.Error("Failed to delete attached file '{File}'", e, file); } }); } diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index a551ac181f..51f3117a40 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -73,11 +73,11 @@ namespace Umbraco.Core.IO } catch (UnauthorizedAccessException ex) { - Current.Logger.Error("Not authorized to get directories", ex); + Current.Logger.Error("Not authorized to get directories for '{Path}'", ex, fullPath); } catch (DirectoryNotFoundException ex) { - Current.Logger.Error("Directory not found", ex); + Current.Logger.Error("Directory not found for '{Path}'", ex, fullPath); } return Enumerable.Empty(); @@ -109,7 +109,7 @@ namespace Umbraco.Core.IO } catch (DirectoryNotFoundException ex) { - Current.Logger.Error("Directory not found", ex); + Current.Logger.Error("Directory not found for '{Path}'", ex, fullPath); } } @@ -189,11 +189,11 @@ namespace Umbraco.Core.IO } catch (UnauthorizedAccessException ex) { - Current.Logger.Error("Not authorized to get directories", ex); + Current.Logger.Error("Not authorized to get directories for '{Path}'", ex, fullPath); } catch (DirectoryNotFoundException ex) { - Current.Logger.Error("Directory not found", ex); + Current.Logger.Error("Directory not found for '{FullPath}'", ex, fullPath); } return Enumerable.Empty(); diff --git a/src/Umbraco.Core/Logging/LoggerExtensions.cs b/src/Umbraco.Core/Logging/LoggerExtensions.cs index 778675b72f..df939582b8 100644 --- a/src/Umbraco.Core/Logging/LoggerExtensions.cs +++ b/src/Umbraco.Core/Logging/LoggerExtensions.cs @@ -14,7 +14,6 @@ namespace Umbraco.Core.Logging /// The logger. /// A message. /// An exception. - //[Obsolete("Use the Error with message template", true)] public static void Error(this ILogger logger, string message, Exception exception = null) { logger.Error(typeof(T), message, exception); diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index adf3418fb0..fe5fe80363 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -81,7 +81,7 @@ namespace Umbraco.Core.Manifest } catch (Exception e) { - _logger.Error($"Failed to parse manifest at \"{path}\", ignoring.", e); + _logger.Error($"Failed to parse manifest at '{Path}', ignoring.", e, path); } } diff --git a/src/Umbraco.Core/Manifest/ManifestWatcher.cs b/src/Umbraco.Core/Manifest/ManifestWatcher.cs index 3bc70e2d78..4c0ddbf822 100644 --- a/src/Umbraco.Core/Manifest/ManifestWatcher.cs +++ b/src/Umbraco.Core/Manifest/ManifestWatcher.cs @@ -54,7 +54,7 @@ namespace Umbraco.Core.Manifest if (_isRestarting) return; _isRestarting = true; - _logger.Info("manifest has changed, app pool is restarting (" + e.FullPath + ")"); + _logger.Info("Manifest has changed, app pool is restarting ({Path})", e.FullPath); HttpRuntime.UnloadAppDomain(); Dispose(); // uh? if the app restarts then this should be disposed anyways? } diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs b/src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs index ec77d2e0d4..bb8833e5cf 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseSchemaCreator.cs @@ -109,7 +109,7 @@ namespace Umbraco.Core.Migrations.Install { //swallow this for now, not sure how best to handle this with diff databases... though this is internal // and only used for unit tests. If this fails its because the table doesn't exist... generally! - _logger.Error("Could not drop table " + tableName, ex); + _logger.Error("Could not drop table {TableName}", ex, tableName); } } } diff --git a/src/Umbraco.Core/Models/MediaExtensions.cs b/src/Umbraco.Core/Models/MediaExtensions.cs index 1f219d5e10..5d0c911663 100644 --- a/src/Umbraco.Core/Models/MediaExtensions.cs +++ b/src/Umbraco.Core/Models/MediaExtensions.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Models } catch (Exception ex) { - logger.Error("Could not parse the string " + jsonString + " to a json object", ex); + logger.Error("Could not parse the string '{JsonString}' to a json object", ex, jsonString); return string.Empty; } } diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index e0d52f7077..e3dc922e36 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -552,9 +552,15 @@ namespace Umbraco.Core.Models private Attempt WarnIfPropertyTypeNotFoundOnGet(string propertyAlias, string propertyName, T defaultVal) { void DoLog(string logPropertyAlias, string logPropertyName) - => Current.Logger.Warn($"Trying to access the '{logPropertyName}' property on " + typeof(Member) - + $" but the {logPropertyAlias} property does not exist on the member type so a default value is returned. Ensure that you have a property type with alias: " - + logPropertyAlias + $" configured on your member type in order to use the '{logPropertyName}' property on the model correctly."); + { + //WB: TODO Check that we do not need to specify properties again if used later on again in message template + Current.Logger.Warn("Trying to access the '{PropertyName}' property on '{MemberType}' " + + "but the {PropertyAlias} property does not exist on the member type so a default value is returned. " + + "Ensure that you have a property type with alias: {PropertyAlias} configured on your member type in order to use the '{PropertyName}' property on the model correctly.", + logPropertyName, + typeof(Member), + logPropertyAlias); + } // if the property doesn't exist, if (Properties.Contains(propertyAlias) == false) @@ -572,8 +578,13 @@ namespace Umbraco.Core.Models private bool WarnIfPropertyTypeNotFoundOnSet(string propertyAlias, string propertyName) { void DoLog(string logPropertyAlias, string logPropertyName) - => Current.Logger.Warn($"An attempt was made to set a value on the property '{logPropertyName}' on type " + typeof(Member) - + $" but the property type {logPropertyAlias} does not exist on the member type, ensure that this property type exists so that setting this property works correctly."); + { + Current.Logger.Warn("An attempt was made to set a value on the property '{PropertyName}' on type typeof(Member) but the " + + "property type {PropertyAlias} does not exist on the member type, ensure that this property type exists so that setting this property works correctly.", + logPropertyName, + typeof(Member), + logPropertyAlias); + } // if the property doesn't exist, if (Properties.Contains(propertyAlias) == false) diff --git a/src/Umbraco.Core/Packaging/PackageBinaryInspector.cs b/src/Umbraco.Core/Packaging/PackageBinaryInspector.cs index b392aca289..adf90147f8 100644 --- a/src/Umbraco.Core/Packaging/PackageBinaryInspector.cs +++ b/src/Umbraco.Core/Packaging/PackageBinaryInspector.cs @@ -192,7 +192,7 @@ namespace Umbraco.Core.Packaging assemblyName.Name, "' see error log for full details.")); assembliesWithErrors.Add(a); - Current.Logger.Error("An error occurred scanning package assemblies", ex); + Current.Logger.Error("An error occurred scanning package assembly '{AssemblyName}'", ex, assemblyName.FullName); } } } @@ -236,7 +236,7 @@ namespace Umbraco.Core.Packaging a.GetName().Name, "' see error log for full details.")); assembliesWithErrors.Add(a); - Current.Logger.Error("An error occurred scanning package assemblies", ex); + Current.Logger.Error("An error occurred scanning package assembly '{AssemblyName}'", ex, a.GetName().FullName); } } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 13812662bd..2e0139aa30 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -487,10 +487,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (result.ContainsKey(temp.VersionId)) { - var msg = $"The query returned multiple property sets for content {temp.Id}, {temp.ContentType.Name}"; if (ContentRepositoryBase.ThrowOnWarning) - throw new InvalidOperationException(msg); - Logger.Warn>(msg); + throw new InvalidOperationException($"The query returned multiple property sets for content {temp.Id}, {temp.ContentType.Name}"); + Logger.Warn>("The query returned multiple property sets for content {ContentId}, {ContentTypeName}", temp.Id, temp.ContentType.Name); } result[temp.VersionId] = new PropertyCollection(properties); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepository.cs index 8ba25b2a50..8d28b74c46 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepository.cs @@ -227,9 +227,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { if (string.IsNullOrWhiteSpace(entity.Alias)) { - var m = $"ContentType '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; - var e = new Exception(m); - Logger.Error(m, e); + var e = new Exception($"ContentType '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."); + Logger.Error("ContentType '{EntityName}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", e, entity.Name); throw e; } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index 19f9afb7aa..91e9b12704 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -521,9 +521,12 @@ AND umbracoNode.id <> @id", { if (string.IsNullOrWhiteSpace(pt.Alias)) { - var m = $"Property Type '{pt.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; - var e = new InvalidOperationException(m); - Logger.Error>(m, e); + var e = new InvalidOperationException($"Property Type '{pt.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."); + + Logger.Error>( + "Property Type '{PropertyTypeName}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", + e, pt.Name); + throw e; } } @@ -532,10 +535,14 @@ AND umbracoNode.id <> @id", { if (string.IsNullOrWhiteSpace(entity.Alias)) { - var m = $"{typeof(TEntity).Name} '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; - var e = new InvalidOperationException(m); - Logger.Error>(m, e); - throw e; + var ex = new InvalidOperationException($"{typeof(TEntity).Name} '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."); + + Logger.Error>("{EntityTypeName} '{EntityName}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", + ex, + typeof(TEntity).Name, + entity.Name); + + throw ex; } } diff --git a/src/Umbraco.Core/Persistence/UmbracoDatabase.cs b/src/Umbraco.Core/Persistence/UmbracoDatabase.cs index 082f381523..3b3122299e 100644 --- a/src/Umbraco.Core/Persistence/UmbracoDatabase.cs +++ b/src/Umbraco.Core/Persistence/UmbracoDatabase.cs @@ -190,13 +190,13 @@ namespace Umbraco.Core.Persistence } #endif - protected override void OnException(Exception x) + protected override void OnException(Exception ex) { - _logger.Error("Exception (" + InstanceId + ").", x); + _logger.Error("Exception ({InstanceId}).", ex, InstanceId); _logger.Debug("At:\r\n{StackTrace}", Environment.StackTrace); if (EnableSqlTrace == false) _logger.Debug("Sql:\r\n{Sql}", CommandToString(LastSQL, LastArgs)); - base.OnException(x); + base.OnException(ex); } private DbCommand _cmd; diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs index 5a642bedc7..8e63a236f8 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters } catch (Exception ex) { - Current.Logger.Error("Could not parse the string " + sourceString + " to a json object", ex); + Current.Logger.Error("Could not parse the string '{JsonString}' to a json object", ex, sourceString); } } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs index 413e66afb7..29b3802e45 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs @@ -43,7 +43,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters catch (Exception ex) { // cannot deserialize, assume it may be a raw image url - Current.Logger.Error($"Could not deserialize string \"{sourceString}\" into an image cropper value.", ex); + Current.Logger.Error("Could not deserialize string '{JsonString}' into an image cropper value.", ex, sourceString); value = new ImageCropperValue { Src = sourceString }; } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs index aeeb1a795f..ff4ccb8260 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs @@ -57,7 +57,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters } catch (Exception ex) { - Current.Logger.Error("Could not parse the string " + sourceString + " to a json object", ex); + Current.Logger.Error("Could not parse the string '{JsonString}' to a json object", ex, sourceString); } } diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index af49cc108b..3a027925c1 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -1240,11 +1240,11 @@ namespace Umbraco.Core.Services.Implement d.PublishCulture(); // fixme variants? result = SaveAndPublish(d, userId: d.WriterId); if (result.Success == false) - Logger.Error($"Failed to publish document id={d.Id}, reason={result.Result}."); + Logger.Error("Failed to publish document id={DocumentId}, reason={Reason}.", null, d.Id, result.Result); } catch (Exception e) { - Logger.Error($"Failed to publish document id={d.Id}, an exception was thrown.", e); + Logger.Error("Failed to publish document id={DocumentId}, an exception was thrown.", e, d.Id); throw; } yield return result; @@ -1256,11 +1256,11 @@ namespace Umbraco.Core.Services.Implement d.ExpireDate = null; var result = Unpublish(d, userId: d.WriterId); if (result.Success == false) - Logger.Error($"Failed to unpublish document id={d.Id}, reason={result.Result}."); + Logger.Error("Failed to unpublish document id={DocumentId}, reason={Reason}.", null, d.Id, result.Result); } catch (Exception e) { - Logger.Error($"Failed to unpublish document id={d.Id}, an exception was thrown.", e); + Logger.Error("Failed to unpublish document id={DocumentId}, an exception was thrown.", e, d.Id); throw; } } @@ -1439,7 +1439,7 @@ namespace Umbraco.Core.Services.Implement // fixme not going to work, do it differently _mediaFileSystem.DeleteFiles(args.MediaFilesToDelete, // remove flagged files - (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: " + file, e)); + (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: {File}", e, file)); } } diff --git a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs index 32725313f5..23d5fffb03 100644 --- a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs +++ b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs @@ -204,7 +204,7 @@ namespace Umbraco.Core.Services.Implement } catch (Exception ex) { - _logger.Error("Could not load file into XML " + supplementaryFile.File.FullName, ex); + _logger.Error("Could not load file into XML {File}", ex, supplementaryFile.File.FullName); continue; } diff --git a/src/Umbraco.Core/Services/Implement/MediaService.cs b/src/Umbraco.Core/Services/Implement/MediaService.cs index d29875d68b..27bf36328f 100644 --- a/src/Umbraco.Core/Services/Implement/MediaService.cs +++ b/src/Umbraco.Core/Services/Implement/MediaService.cs @@ -892,7 +892,7 @@ namespace Umbraco.Core.Services.Implement scope.Events.Dispatch(Deleted, this, args); _mediaFileSystem.DeleteFiles(args.MediaFilesToDelete, // remove flagged files - (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: " + file, e)); + (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: {File}", e, file)); } } diff --git a/src/Umbraco.Core/Services/Implement/MemberService.cs b/src/Umbraco.Core/Services/Implement/MemberService.cs index ca2b39dee2..c42007e254 100644 --- a/src/Umbraco.Core/Services/Implement/MemberService.cs +++ b/src/Umbraco.Core/Services/Implement/MemberService.cs @@ -930,7 +930,7 @@ namespace Umbraco.Core.Services.Implement // fixme - this is MOOT because the event will not trigger immediately // it's been refactored already (think it's the dispatcher that deals with it?) _mediaFileSystem.DeleteFiles(args.MediaFilesToDelete, // remove flagged files - (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: " + file, e)); + (file, e) => Logger.Error("An error occurred while deleting file attached to nodes: {File}", e, file)); } #endregion diff --git a/src/Umbraco.Core/Services/Implement/PackagingService.cs b/src/Umbraco.Core/Services/Implement/PackagingService.cs index ec24f481df..3d4d00e9a4 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -491,7 +491,7 @@ namespace Umbraco.Core.Services.Implement var tryCreateFolder = _contentTypeService.CreateContainer(-1, rootFolder); if (tryCreateFolder == false) { - _logger.Error("Could not create folder: " + rootFolder, tryCreateFolder.Exception); + _logger.Error("Could not create folder: {FolderName}", tryCreateFolder.Exception, rootFolder); throw tryCreateFolder.Exception; } var rootFolderId = tryCreateFolder.Result.Entity.Id; @@ -525,7 +525,7 @@ namespace Umbraco.Core.Services.Implement var tryCreateFolder = _contentTypeService.CreateContainer(current.Id, folderName); if (tryCreateFolder == false) { - _logger.Error("Could not create folder: " + folderName, tryCreateFolder.Exception); + _logger.Error("Could not create folder: {FolderName}", tryCreateFolder.Exception, folderName); throw tryCreateFolder.Exception; } return _contentTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); @@ -949,7 +949,7 @@ namespace Umbraco.Core.Services.Implement var tryCreateFolder = _dataTypeService.CreateContainer(-1, rootFolder); if (tryCreateFolder == false) { - _logger.Error("Could not create folder: " + rootFolder, tryCreateFolder.Exception); + _logger.Error("Could not create folder: {FolderName}", tryCreateFolder.Exception, rootFolder); throw tryCreateFolder.Exception; } current = _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); @@ -982,7 +982,7 @@ namespace Umbraco.Core.Services.Implement var tryCreateFolder = _dataTypeService.CreateContainer(current.Id, folderName); if (tryCreateFolder == false) { - _logger.Error("Could not create folder: " + folderName, tryCreateFolder.Exception); + _logger.Error("Could not create folder: {FolderName}", tryCreateFolder.Exception, folderName); throw tryCreateFolder.Exception; } return _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); @@ -1529,7 +1529,10 @@ namespace Umbraco.Core.Services.Implement else if (string.IsNullOrEmpty((string)elementCopy.Element("Master")) == false && templateElements.Any(x => (string)x.Element("Alias") == (string)elementCopy.Element("Master")) == false) { - _logger.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", (string)elementCopy.Element("Alias"), (string)elementCopy.Element("Master"))); + _logger.Info( + "Template '{TemplateAlias}' has an invalid Master '{TemplateMaster}', so the reference has been ignored.", + (string) elementCopy.Element("Alias"), + (string) elementCopy.Element("Master")); } graph.AddItem(TopoGraph.CreateNode((string) elementCopy.Element("Alias"), elementCopy, dependencies)); diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index a8505a1f77..6f89f1233e 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -352,7 +352,11 @@ namespace Umbraco.Core.Sync } catch (JsonException ex) { - Logger.Error($"Failed to deserialize instructions ({dto.Id}: \"{dto.Instructions}\").", ex); + Logger.Error("Failed to deserialize instructions ({DtoId}: '{DtoInstructions}').", + ex, + dto.Id, + dto.Instructions); + lastId = dto.Id; // skip continue; } @@ -408,7 +412,10 @@ namespace Umbraco.Core.Sync catch (Exception ex) { Logger.Error( - $"DISTRIBUTED CACHE IS NOT UPDATED. Failed to execute instructions ({dto.Id}: \"{dto.Instructions}\"). Instruction is being skipped/ignored", ex); + "DISTRIBUTED CACHE IS NOT UPDATED. Failed to execute instructions ({DtoId}: '{DtoInstructions}'). Instruction is being skipped/ignored", + ex, + dto.Id, + dto.Instructions); //we cannot throw here because this invalid instruction will just keep getting processed over and over and errors // will be thrown over and over. The only thing we can do is ignore and move on. diff --git a/src/Umbraco.Core/UmbracoApplicationBase.cs b/src/Umbraco.Core/UmbracoApplicationBase.cs index 3888b0c787..91d390b308 100644 --- a/src/Umbraco.Core/UmbracoApplicationBase.cs +++ b/src/Umbraco.Core/UmbracoApplicationBase.cs @@ -185,14 +185,15 @@ namespace Umbraco.Core BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null); - var shutdownMsg = $"Application shutdown. Details: {HostingEnvironment.ShutdownReason}\r\n\r\n_shutDownMessage={shutDownMessage}\r\n\r\n_shutDownStack={shutDownStack}"; - - logger.Info(shutdownMsg); + logger.Info("Application shutdown. Details: {ShutdownReason}\r\n\r\n_shutDownMessage={ShutdownMessage}\r\n\r\n_shutDownStack={ShutdownStack}", + HostingEnvironment.ShutdownReason, + shutDownMessage, + shutDownStack); } catch (Exception) { //if for some reason that fails, then log the normal output - logger.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); + logger.Info("Application shutdown. Reason: {ShutdownReason}", HostingEnvironment.ShutdownReason); } } @@ -224,7 +225,7 @@ namespace Umbraco.Core // ignore HTTP errors if (exception.GetType() == typeof(HttpException)) return; - Current.Logger.Error("An unhandled exception occurred.", exception); + Current.Logger.Error("An unhandled exception occurred", exception); } // called by ASP.NET (auto event wireup) at any phase in the application life cycle @@ -247,7 +248,7 @@ namespace Umbraco.Core } catch (Exception ex) { - Current.Logger.Error($"Error in {name} handler.", ex); + Current.Logger.Error("Error in {Name} handler.", ex, name); throw; } }