From 7e4f2957a3d0c9a774ed5f3aa4c0b928242b309a Mon Sep 17 00:00:00 2001 From: lkoruba Date: Fri, 29 Jun 2018 14:53:41 +0200 Subject: [PATCH 1/4] Change calls to logger.Warn method to use Func parameter --- src/Umbraco.Core/Components/BootLoader.cs | 2 +- .../Upgrade/V_8_0_0/RefactorXmlColumns.cs | 2 +- .../Persistence/DbConnectionExtensions.cs | 2 +- .../Implement/ContentTypeRepositoryBase.cs | 2 +- .../PropertyEditors/DataValueEditor.cs | 2 +- src/Umbraco.Core/Runtime/CoreRuntime.cs | 2 +- src/Umbraco.Core/Scoping/ScopeProvider.cs | 2 +- .../LocalizedTextServiceFileSources.cs | 3 +-- .../Services/Implement/PackagingService.cs | 21 +++++++------------ .../Services/Implement/UserService.cs | 2 +- .../Sync/DatabaseServerMessenger.cs | 4 ++-- src/Umbraco.Web/Editors/PasswordChanger.cs | 10 ++++----- src/Umbraco.Web/Macros/MacroRenderer.cs | 2 +- .../Macros/UserControlMacroEngine.cs | 4 ++-- .../ImageCropperPropertyValueEditor.cs | 2 +- 15 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/Umbraco.Core/Components/BootLoader.cs b/src/Umbraco.Core/Components/BootLoader.cs index f11657d634..35ab6ff79a 100644 --- a/src/Umbraco.Core/Components/BootLoader.cs +++ b/src/Umbraco.Core/Components/BootLoader.cs @@ -347,7 +347,7 @@ namespace Umbraco.Core.Components { if (_booted == false) { - _proflog.Logger.Warn("Cannot terminate, has not booted."); + _proflog.Logger.Warn(() => "Cannot terminate, has not booted."); return; } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RefactorXmlColumns.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RefactorXmlColumns.cs index b7d869ee62..0becdc5a8c 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RefactorXmlColumns.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RefactorXmlColumns.cs @@ -37,7 +37,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 var keyName = c.Item3.ToLowerInvariant(); if (dups.Contains(keyName)) { - Logger.Warn("Duplicate constraint " + c.Item3); + Logger.Warn(() => $"Duplicate constraint {c.Item3}"); continue; } dups.Add(keyName); diff --git a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs index 8f501c0aaa..0bbce78223 100644 --- a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs +++ b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs @@ -65,7 +65,7 @@ namespace Umbraco.Core.Persistence catch (DbException e) { // Don't swallow this error, the exception is super handy for knowing "why" its not available - Current.Logger.Warn(e, "Configured database is reporting as not being available."); + Current.Logger.Warn(e, () => "Configured database is reporting as not being available."); return false; } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index d33980ac46..051cdebd2b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -563,7 +563,7 @@ AND umbracoNode.id <> @id", } else { - Logger.Warn>("Could not assign a data type for the property type " + propertyType.Alias + " since no data type was found with a property editor " + propertyType.PropertyEditorAlias); + Logger.Warn>(() => $"Could not assign a data type for the property type {propertyType.Alias} since no data type was found with a property editor {propertyType.PropertyEditorAlias}"); } } } diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index f235a95aa8..e8d16fcd62 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -261,7 +261,7 @@ namespace Umbraco.Core.PropertyEditors var result = TryConvertValueToCrlType(editorValue.Value); if (result.Success == false) { - Current.Logger.Warn("The value " + editorValue.Value + " cannot be converted to the type " + ValueTypes.ToStorageType(ValueType)); + Current.Logger.Warn(() => $"The value {editorValue.Value} cannot be converted to the type {ValueTypes.ToStorageType(ValueType)}"); return null; } return result.Result; diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index a3652b3330..4ea4361972 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -315,7 +315,7 @@ namespace Umbraco.Core.Runtime catch (Exception e) { // can connect to the database but cannot access the migration table... need to install - logger.Warn(e, "Could not check the upgrade state."); + logger.Warn(e, () => "Could not check the upgrade state."); logger.Debug("Could not check the upgrade state, need to install Umbraco."); _state.Level = RuntimeLevel.Install; return; diff --git a/src/Umbraco.Core/Scoping/ScopeProvider.cs b/src/Umbraco.Core/Scoping/ScopeProvider.cs index db45ca2754..beb1ee5374 100644 --- a/src/Umbraco.Core/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Core/Scoping/ScopeProvider.cs @@ -117,7 +117,7 @@ namespace Umbraco.Core.Scoping } // hard to inject into a static method :( - Current.Logger.Warn("Missed " + typeof(T).Name + " Object " + objectKey.ToString("N").Substring(0, 8)); + Current.Logger.Warn(() => $"Missed {typeof(T).Name} Object {objectKey.ToString("N").Substring(0, 8)}"); #if DEBUG_SCOPES //Current.Logger.Debug("At:\r\n" + Head(Environment.StackTrace, 24)); #endif diff --git a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs index 801d35d806..44587b616b 100644 --- a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs +++ b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs @@ -88,8 +88,7 @@ namespace Umbraco.Core.Services.Implement } catch (CultureNotFoundException) { - Current.Logger.Warn( - string.Format("The culture {0} found in the file {1} is not a valid culture", cultureVal, fileInfo.FullName)); + Current.Logger.Warn(() => $"The culture {cultureVal} found in the file {fileInfo.FullName} is not a valid culture"); //If the culture in the file is invalid, we'll just hope the file name is a valid culture below, otherwise // an exception will be thrown. } diff --git a/src/Umbraco.Core/Services/Implement/PackagingService.cs b/src/Umbraco.Core/Services/Implement/PackagingService.cs index 1e585053da..9c51b3081b 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -631,10 +631,7 @@ namespace Umbraco.Core.Services.Implement } else { - _logger.Warn( - string.Format( - "Packager: Error handling allowed templates. Template with alias '{0}' could not be found.", - alias)); + _logger.Warn(() => $"Packager: Error handling allowed templates. Template with alias '{alias}' could not be found."); } } @@ -650,10 +647,7 @@ namespace Umbraco.Core.Services.Implement } else { - _logger.Warn( - string.Format( - "Packager: Error handling default template. Default template with alias '{0}' could not be found.", - defaultTemplateElement.Value)); + _logger.Warn(() => $"Packager: Error handling default template. Default template with alias '{defaultTemplateElement.Value}' could not be found."); } } } @@ -724,11 +718,10 @@ namespace Umbraco.Core.Services.Implement // This means that the property will not be created. if (dataTypeDefinition == null) { - _logger.Warn( - string.Format("Packager: Error handling creation of PropertyType '{0}'. Could not find DataTypeDefintion with unique id '{1}' nor one referencing the DataType with a property editor alias (or legacy control id) '{2}'. Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists.", - property.Element("Name").Value, - dataTypeDefinitionId, - property.Element("Type").Value.Trim())); + _logger.Warn(() => $"Packager: Error handling creation of PropertyType '{property.Element("Name").Value}'. " + + $"Could not find DataTypeDefintion with unique id '{dataTypeDefinitionId}' nor one referencing the DataType with a " + + $"property editor alias (or legacy control id) '{property.Element("Type").Value.Trim()}'. " + + $"Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists."); //convert to a label! dataTypeDefinition = _dataTypeService.GetByEditorAlias(Constants.PropertyEditors.Aliases.NoEdit).FirstOrDefault(); @@ -772,7 +765,7 @@ namespace Umbraco.Core.Services.Implement var allowedChild = _importedContentTypes.ContainsKey(alias) ? _importedContentTypes[alias] : _contentTypeService.Get(alias); if (allowedChild == null) { - _logger.Warn($"Packager: Error handling DocumentType structure. DocumentType with alias '{alias}' could not be found and was not added to the structure for '{contentType.Alias}'."); + _logger.Warn(() => $"Packager: Error handling DocumentType structure. DocumentType with alias '{alias}' could not be found and was not added to the structure for '{contentType.Alias}'."); continue; } diff --git a/src/Umbraco.Core/Services/Implement/UserService.cs b/src/Umbraco.Core/Services/Implement/UserService.cs index 96cac1d814..30428e694c 100644 --- a/src/Umbraco.Core/Services/Implement/UserService.cs +++ b/src/Umbraco.Core/Services/Implement/UserService.cs @@ -333,7 +333,7 @@ namespace Umbraco.Core.Services.Implement // if we are upgrading and an exception occurs, log and swallow it if (_isUpgrading == false) throw; - Logger.Warn(ex, "An error occurred attempting to save a user instance during upgrade, normally this warning can be ignored"); + Logger.Warn(ex, () => "An error occurred attempting to save a user instance during upgrade, normally this warning can be ignored"); // we don't want the uow to rollback its scope! scope.Complete(); diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index a1b89e58bc..35b5334801 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -142,7 +142,7 @@ namespace Umbraco.Core.Sync var idle =_syncIdle.WaitOne(5000); if (idle == false) { - Logger.Warn("The wait lock timed out, application is shutting down. The current instruction batch will be re-processed."); + Logger.Warn(() => "The wait lock timed out, application is shutting down. The current instruction batch will be re-processed."); } }, weight); @@ -178,7 +178,7 @@ namespace Umbraco.Core.Sync { // we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new // server and it will need to rebuild it's own caches, eg Lucene or the xml cache file. - Logger.Warn("No last synced Id found, this generally means this is a new server/install." + Logger.Warn(() => "No last synced Id found, this generally means this is a new server/install." + " The server will build its caches and indexes, and then adjust its last synced Id to the latest found in" + " the database and maintain cache updates based on that Id."); diff --git a/src/Umbraco.Web/Editors/PasswordChanger.cs b/src/Umbraco.Web/Editors/PasswordChanger.cs index 08f010ecd4..7aa8c88848 100644 --- a/src/Umbraco.Web/Editors/PasswordChanger.cs +++ b/src/Umbraco.Web/Editors/PasswordChanger.cs @@ -188,7 +188,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, "Could not reset member password"); + _logger.Warn(ex, () => "Could not reset member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not reset password, error: " + ex.Message + " (see log for full details)", new[] { "resetPassword" }) }); } } @@ -213,7 +213,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, "Could not change member password"); + _logger.Warn(ex, () => "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex.Message + " (see log for full details)", new[] { "value" }) }); } } @@ -242,7 +242,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, "Could not change member password"); + _logger.Warn(ex, () => "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex.Message + " (see log for full details)", new[] { "value" }) }); } } @@ -274,14 +274,14 @@ namespace Umbraco.Web.Editors } catch (Exception ex1) { - _logger.Warn(ex1, "Could not change member password"); + _logger.Warn(ex1, () => "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex1.Message + " (see log for full details)", new[] { "value" }) }); } } catch (Exception ex2) { - _logger.Warn(ex2, "Could not retrieve member password"); + _logger.Warn(ex2, () => "Could not retrieve member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex2.Message + " (see log for full details)", new[] { "value" }) }); } } diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 8320e881b1..cf8dcb76d5 100644 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -304,7 +304,7 @@ namespace Umbraco.Web.Macros { Exceptions.Add(e); - _plogger.Logger.Warn(e, "Failed " + msgIn); + _plogger.Logger.Warn(e, () => $"Failed {msgIn}"); var macroErrorEventArgs = new MacroErrorEventArgs { diff --git a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs index 67122f9f56..98246084f9 100644 --- a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs +++ b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs @@ -78,12 +78,12 @@ namespace Umbraco.Web.Macros } catch (Exception e) { - Current.Logger.Warn(e, $"Failed to set property \"{modelProperty.Key}\" value \"{modelProperty.Value}\"."); + Current.Logger.Warn(e, () => $"Failed to set property \"{modelProperty.Key}\" value \"{modelProperty.Value}\"."); } } else { - Current.Logger.Warn($"Failed to set property \"{modelProperty.Key}\" value \"{modelProperty.Value}\"."); + Current.Logger.Warn(() => $"Failed to set property \"{modelProperty.Key}\" value \"{modelProperty.Value}\"."); } } } diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index 98e8346441..2e873b5178 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.PropertyEditors catch (Exception ex) { // for some reason the value is invalid so continue as if there was no value there - _logger.Warn(ex, "Could not parse current db value to a JObject."); + _logger.Warn(ex, () => "Could not parse current db value to a JObject."); } if (string.IsNullOrWhiteSpace(currentPath) == false) currentPath = _mediaFileSystem.GetRelativePath(currentPath); From 8359ea5862afe8dd0e020f18e26d7229b0807d1a Mon Sep 17 00:00:00 2001 From: lkoruba Date: Fri, 29 Jun 2018 15:08:35 +0200 Subject: [PATCH 2/4] Revoke files where string is not concatenated --- src/Umbraco.Core/Components/BootLoader.cs | 2 +- src/Umbraco.Core/Persistence/DbConnectionExtensions.cs | 2 +- src/Umbraco.Core/Runtime/CoreRuntime.cs | 2 +- src/Umbraco.Core/Services/Implement/UserService.cs | 2 +- src/Umbraco.Core/Sync/DatabaseServerMessenger.cs | 4 ++-- src/Umbraco.Web/Editors/PasswordChanger.cs | 10 +++++----- .../PropertyEditors/ImageCropperPropertyValueEditor.cs | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Components/BootLoader.cs b/src/Umbraco.Core/Components/BootLoader.cs index 35ab6ff79a..f11657d634 100644 --- a/src/Umbraco.Core/Components/BootLoader.cs +++ b/src/Umbraco.Core/Components/BootLoader.cs @@ -347,7 +347,7 @@ namespace Umbraco.Core.Components { if (_booted == false) { - _proflog.Logger.Warn(() => "Cannot terminate, has not booted."); + _proflog.Logger.Warn("Cannot terminate, has not booted."); return; } diff --git a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs index 0bbce78223..8f501c0aaa 100644 --- a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs +++ b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs @@ -65,7 +65,7 @@ namespace Umbraco.Core.Persistence catch (DbException e) { // Don't swallow this error, the exception is super handy for knowing "why" its not available - Current.Logger.Warn(e, () => "Configured database is reporting as not being available."); + Current.Logger.Warn(e, "Configured database is reporting as not being available."); return false; } diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 4ea4361972..a3652b3330 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -315,7 +315,7 @@ namespace Umbraco.Core.Runtime catch (Exception e) { // can connect to the database but cannot access the migration table... need to install - logger.Warn(e, () => "Could not check the upgrade state."); + logger.Warn(e, "Could not check the upgrade state."); logger.Debug("Could not check the upgrade state, need to install Umbraco."); _state.Level = RuntimeLevel.Install; return; diff --git a/src/Umbraco.Core/Services/Implement/UserService.cs b/src/Umbraco.Core/Services/Implement/UserService.cs index 30428e694c..96cac1d814 100644 --- a/src/Umbraco.Core/Services/Implement/UserService.cs +++ b/src/Umbraco.Core/Services/Implement/UserService.cs @@ -333,7 +333,7 @@ namespace Umbraco.Core.Services.Implement // if we are upgrading and an exception occurs, log and swallow it if (_isUpgrading == false) throw; - Logger.Warn(ex, () => "An error occurred attempting to save a user instance during upgrade, normally this warning can be ignored"); + Logger.Warn(ex, "An error occurred attempting to save a user instance during upgrade, normally this warning can be ignored"); // we don't want the uow to rollback its scope! scope.Complete(); diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 35b5334801..a1b89e58bc 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -142,7 +142,7 @@ namespace Umbraco.Core.Sync var idle =_syncIdle.WaitOne(5000); if (idle == false) { - Logger.Warn(() => "The wait lock timed out, application is shutting down. The current instruction batch will be re-processed."); + Logger.Warn("The wait lock timed out, application is shutting down. The current instruction batch will be re-processed."); } }, weight); @@ -178,7 +178,7 @@ namespace Umbraco.Core.Sync { // we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new // server and it will need to rebuild it's own caches, eg Lucene or the xml cache file. - Logger.Warn(() => "No last synced Id found, this generally means this is a new server/install." + Logger.Warn("No last synced Id found, this generally means this is a new server/install." + " The server will build its caches and indexes, and then adjust its last synced Id to the latest found in" + " the database and maintain cache updates based on that Id."); diff --git a/src/Umbraco.Web/Editors/PasswordChanger.cs b/src/Umbraco.Web/Editors/PasswordChanger.cs index 7aa8c88848..08f010ecd4 100644 --- a/src/Umbraco.Web/Editors/PasswordChanger.cs +++ b/src/Umbraco.Web/Editors/PasswordChanger.cs @@ -188,7 +188,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, () => "Could not reset member password"); + _logger.Warn(ex, "Could not reset member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not reset password, error: " + ex.Message + " (see log for full details)", new[] { "resetPassword" }) }); } } @@ -213,7 +213,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, () => "Could not change member password"); + _logger.Warn(ex, "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex.Message + " (see log for full details)", new[] { "value" }) }); } } @@ -242,7 +242,7 @@ namespace Umbraco.Web.Editors } catch (Exception ex) { - _logger.Warn(ex, () => "Could not change member password"); + _logger.Warn(ex, "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex.Message + " (see log for full details)", new[] { "value" }) }); } } @@ -274,14 +274,14 @@ namespace Umbraco.Web.Editors } catch (Exception ex1) { - _logger.Warn(ex1, () => "Could not change member password"); + _logger.Warn(ex1, "Could not change member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex1.Message + " (see log for full details)", new[] { "value" }) }); } } catch (Exception ex2) { - _logger.Warn(ex2, () => "Could not retrieve member password"); + _logger.Warn(ex2, "Could not retrieve member password"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, error: " + ex2.Message + " (see log for full details)", new[] { "value" }) }); } } diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index 2e873b5178..98e8346441 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -78,7 +78,7 @@ namespace Umbraco.Web.PropertyEditors catch (Exception ex) { // for some reason the value is invalid so continue as if there was no value there - _logger.Warn(ex, () => "Could not parse current db value to a JObject."); + _logger.Warn(ex, "Could not parse current db value to a JObject."); } if (string.IsNullOrWhiteSpace(currentPath) == false) currentPath = _mediaFileSystem.GetRelativePath(currentPath); From b515f24c16649a966a6df5693ebf69985f51e1b0 Mon Sep 17 00:00:00 2001 From: lkoruba Date: Fri, 29 Jun 2018 15:35:56 +0200 Subject: [PATCH 3/4] Change calls to logger.Warn method to use Func second part --- src/Umbraco.Web/BatchedDatabaseServerMessenger.cs | 3 +-- src/Umbraco.Web/Editors/PasswordChanger.cs | 4 ++-- src/Umbraco.Web/HealthCheck/HealthCheckResults.cs | 6 +++--- src/Umbraco.Web/Macros/UserControlMacroEngine.cs | 2 +- .../Mapping/DataTypeConfigurationFieldDisplayResolver.cs | 2 +- src/Umbraco.Web/Models/Mapping/MacroMapperProfile.cs | 2 +- .../ValueConverters/RelatedLinksValueConverter.cs | 2 +- .../PublishedCache/NuCache/DataSource/DatabaseDataSource.cs | 4 ++-- .../XmlPublishedCache/DictionaryPublishedContent.cs | 2 +- src/Umbraco.Web/Security/MembershipHelper.cs | 2 +- .../Security/Providers/UmbracoMembershipProvider.cs | 5 ++--- src/Umbraco.Web/Services/ApplicationTreeService.cs | 2 +- 12 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index 4abb8f1e0b..8929c6edd9 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -40,8 +40,7 @@ namespace Umbraco.Web if (_databaseFactory.CanConnect == false) { - Logger.Warn( - "Cannot connect to the database, distributed calls will not be enabled for this server."); + Logger.Warn("Cannot connect to the database, distributed calls will not be enabled for this server."); } else { diff --git a/src/Umbraco.Web/Editors/PasswordChanger.cs b/src/Umbraco.Web/Editors/PasswordChanger.cs index 08f010ecd4..44042352bb 100644 --- a/src/Umbraco.Web/Editors/PasswordChanger.cs +++ b/src/Umbraco.Web/Editors/PasswordChanger.cs @@ -93,7 +93,7 @@ namespace Umbraco.Web.Editors if (resetResult.Succeeded == false) { var errors = string.Join(". ", resetResult.Errors); - _logger.Warn($"Could not reset user password {errors}"); + _logger.Warn(() => $"Could not reset user password {errors}"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not reset password, errors: " + errors, new[] { "resetPassword" }) }); } @@ -122,7 +122,7 @@ namespace Umbraco.Web.Editors if (changeResult.Succeeded == false) { var errors = string.Join(". ", changeResult.Errors); - _logger.Warn($"Could not change user password {errors}"); + _logger.Warn(() => $"Could not change user password {errors}"); return Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, errors: " + errors, new[] { "oldPassword" }) }); } return Attempt.Succeed(new PasswordChangedModel()); diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs index 139072dcfe..74b44ea7b8 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs @@ -62,16 +62,16 @@ namespace Umbraco.Web.HealthCheck var checkIsSuccess = result.Value.All(x => x.ResultType == StatusResultType.Success); if (checkIsSuccess) { - Logger.Info($" Checks for '{checkName}' all completed succesfully."); + Logger.Info(() => $" Checks for '{checkName}' all completed succesfully."); } else { - Logger.Warn($" Checks for '{checkName}' completed with errors."); + Logger.Warn(() => $" Checks for '{checkName}' completed with errors."); } foreach (var checkResult in checkResults) { - Logger.Info($" Result: {checkResult.ResultType}, Message: '{checkResult.Message}'"); + Logger.Info(() => $" Result: {checkResult.ResultType}, Message: '{checkResult.Message}'"); } } } diff --git a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs index 98246084f9..a0ee2166d7 100644 --- a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs +++ b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs @@ -64,7 +64,7 @@ namespace Umbraco.Web.Macros var controlProperty = type.GetProperty(modelProperty.Key); if (controlProperty == null) { - Current.Logger.Warn($"Control property \"{modelProperty.Key}\" doesn't exist or isn't accessible, skip."); + Current.Logger.Warn(() => $"Control property \"{modelProperty.Key}\" doesn't exist or isn't accessible, skip."); continue; } diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs index 9cdbd6101e..d1838fc0f8 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeConfigurationFieldDisplayResolver.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.Models.Mapping if (configuration.TryGetValue(field.Key, out var value)) field.Value = value; else // weird - just leave the field without a value - but warn - Current.Logger.Warn($"Could not find a value for configuration field \"{field.Key}\"."); + Current.Logger.Warn(() => $"Could not find a value for configuration field \"{field.Key}\"."); } } diff --git a/src/Umbraco.Web/Models/Mapping/MacroMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/MacroMapperProfile.cs index 6eedccf50b..e888d78c07 100644 --- a/src/Umbraco.Web/Models/Mapping/MacroMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/MacroMapperProfile.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.Models.Mapping { //we'll just map this to a text box paramEditor = Current.ParameterEditors[Constants.PropertyEditors.Aliases.TextBox]; - Current.Logger.Warn("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place"); + Current.Logger.Warn(() => $"Could not resolve a parameter editor with alias {property.EditorAlias}, a textbox will be rendered in it's place"); } parameter.View = paramEditor.GetValueEditor().View; diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs index 3a6cc6aa9b..632052d3e7 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs @@ -95,7 +95,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } else { - _logger.Warn($"Related Links value converter skipped a link as the node has been unpublished/deleted (Internal Link NodeId: {relatedLink.Link}, Link Caption: \"{relatedLink.Caption}\")"); + _logger.Warn(() => $"Related Links value converter skipped a link as the node has been unpublished/deleted (Internal Link NodeId: {relatedLink.Link}, Link Caption: \"{relatedLink.Caption}\")"); } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs index fdc18b43aa..0a0c398cd6 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs @@ -186,7 +186,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { if (Debugger.IsAttached) throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding."); - Current.Logger.Warn("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding."); + Current.Logger.Warn(() => $"Missing cmsContentNu edited content for node {dto.Id}, consider rebuilding."); } else { @@ -211,7 +211,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource { if (Debugger.IsAttached) throw new Exception("Missing cmsContentNu published content for node " + dto.Id + ", consider rebuilding."); - Current.Logger.Warn("Missing cmsContentNu published content for node " + dto.Id + ", consider rebuilding."); + Current.Logger.Warn(() => $"Missing cmsContentNu published content for node {dto.Id}, consider rebuilding."); } else { diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs index bc06779db7..9d4dfda461 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs @@ -108,7 +108,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache else { // this is a property that does not correspond to anything, ignore and log - Current.Logger.Warn("Dropping property \"" + i.Key + "\" because it does not belong to the content type."); + Current.Logger.Warn(() => "Dropping property \"" + i.Key + "\" because it does not belong to the content type."); } } } diff --git a/src/Umbraco.Web/Security/MembershipHelper.cs b/src/Umbraco.Web/Security/MembershipHelper.cs index 6d28680877..73eeb89936 100644 --- a/src/Umbraco.Web/Security/MembershipHelper.cs +++ b/src/Umbraco.Web/Security/MembershipHelper.cs @@ -317,7 +317,7 @@ namespace Umbraco.Web.Security if (member == null) { //this should not happen - Current.Logger.Warn("The member validated but then no member was returned with the username " + username); + Current.Logger.Warn(() => $"The member validated but then no member was returned with the username {username}"); return false; } //Log them in diff --git a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs index 04df63a41f..3d45047fb2 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs @@ -149,7 +149,7 @@ namespace Umbraco.Web.Security.Providers if (MemberService.Exists(username)) { status = MembershipCreateStatus.DuplicateUserName; - Current.Logger.Warn>("Cannot create member as username already exists: " + username); + Current.Logger.Warn>(() => $"Cannot create member as username already exists: {username}"); return null; } @@ -157,8 +157,7 @@ namespace Umbraco.Web.Security.Providers if (MemberService.GetByEmail(email) != null && RequiresUniqueEmail) { status = MembershipCreateStatus.DuplicateEmail; - Current.Logger.Warn>( - "Cannot create member as a member with the same email address exists: " + email); + Current.Logger.Warn>(() => $"Cannot create member as a member with the same email address exists: {email}"); return null; } diff --git a/src/Umbraco.Web/Services/ApplicationTreeService.cs b/src/Umbraco.Web/Services/ApplicationTreeService.cs index ef717dc16b..006c0fb07d 100644 --- a/src/Umbraco.Web/Services/ApplicationTreeService.cs +++ b/src/Umbraco.Web/Services/ApplicationTreeService.cs @@ -339,7 +339,7 @@ namespace Umbraco.Web.Services var clrType = Type.GetType(type); if (clrType == null) { - _logger.Warn("The tree definition: " + addElement.ToString() + " could not be resolved to a .Net object type"); + _logger.Warn(() => $"The tree definition: {addElement} could not be resolved to a .Net object type"); continue; } From 549a030d91ceaf0c12d642640fcc85349eae5a88 Mon Sep 17 00:00:00 2001 From: lkoruba Date: Fri, 29 Jun 2018 16:10:04 +0200 Subject: [PATCH 4/4] Fixed concatenation of 4 lines --- src/Umbraco.Core/Services/Implement/PackagingService.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Umbraco.Core/Services/Implement/PackagingService.cs b/src/Umbraco.Core/Services/Implement/PackagingService.cs index 9c51b3081b..54e549dd08 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -718,10 +718,7 @@ namespace Umbraco.Core.Services.Implement // This means that the property will not be created. if (dataTypeDefinition == null) { - _logger.Warn(() => $"Packager: Error handling creation of PropertyType '{property.Element("Name").Value}'. " - + $"Could not find DataTypeDefintion with unique id '{dataTypeDefinitionId}' nor one referencing the DataType with a " - + $"property editor alias (or legacy control id) '{property.Element("Type").Value.Trim()}'. " - + $"Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists."); + _logger.Warn(() => $"Packager: Error handling creation of PropertyType '{property.Element("Name").Value}'. Could not find DataTypeDefintion with unique id '{dataTypeDefinitionId}' nor one referencing the DataType with a property editor alias (or legacy control id) '{property.Element("Type").Value.Trim()}'. Did the package creator forget to package up custom datatypes? This property will be converted to a label/readonly editor if one exists."); //convert to a label! dataTypeDefinition = _dataTypeService.GetByEditorAlias(Constants.PropertyEditors.Aliases.NoEdit).FirstOrDefault();