diff --git a/src/Umbraco.Compat7/Core/Logging/LogHelper.cs b/src/Umbraco.Compat7/Core/Logging/LogHelper.cs index fa94125ce1..060c2b9c53 100644 --- a/src/Umbraco.Compat7/Core/Logging/LogHelper.cs +++ b/src/Umbraco.Compat7/Core/Logging/LogHelper.cs @@ -33,7 +33,7 @@ namespace Umbraco.Core.Logging public static void Warn(Type callingType, string message, params Func[] formatItems) { - Current.Logger.Warn(callingType, message, formatItems); + Current.Logger.Warn(callingType, () => string.Format(message, formatItems.Select(x => x.Invoke()).ToArray())); } [Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")] @@ -47,8 +47,7 @@ namespace Umbraco.Core.Logging HttpContext.Current.Trace.Warn(callingType.Name, string.Format(message, formatItems.Select(x => x.Invoke()).ToArray())); } - Current.Logger.Warn(callingType, message, formatItems); - + Current.Logger.Warn(callingType, () => string.Format(message, formatItems.Select(x => x.Invoke()).ToArray())); } [Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")] @@ -72,7 +71,7 @@ namespace Umbraco.Core.Logging e); } - Current.Logger.Warn(callingType, e, message, formatItems); + Current.Logger.Warn(callingType, e, string.Format(message, formatItems.Select(x => x.Invoke()).ToArray())); } /// @@ -136,7 +135,7 @@ namespace Umbraco.Core.Logging /// The format items. public static void Info(Type type, string generateMessageFormat, params Func[] formatItems) { - Current.Logger.Info(type, generateMessageFormat, formatItems); + Current.Logger.Info(type, string.Format(generateMessageFormat, formatItems.Select(x => x.Invoke()).ToArray())); } /// @@ -182,7 +181,7 @@ namespace Umbraco.Core.Logging /// The format items. public static void Debug(Type type, string generateMessageFormat, params Func[] formatItems) { - Current.Logger.Debug(type, generateMessageFormat, formatItems); + Current.Logger.Debug(type, string.Format(generateMessageFormat, formatItems.Select(x => x.Invoke()).ToArray())); } /// diff --git a/src/Umbraco.Core/Composing/TypeLoader.cs b/src/Umbraco.Core/Composing/TypeLoader.cs index f3cc8e86ff..9ca1b2fa1c 100644 --- a/src/Umbraco.Core/Composing/TypeLoader.cs +++ b/src/Umbraco.Core/Composing/TypeLoader.cs @@ -642,7 +642,7 @@ namespace Umbraco.Core.Composing if (typeList != null) { // need to put some logging here to try to figure out why this is happening: http://issues.umbraco.org/issue/U4-3505 - _logger.Logger.Debug("Getting {0}: found a cached type list.", () => GetName(baseType, attributeType)); + _logger.Logger.Debug(() => $"Getting {GetName(baseType, attributeType)}: found a cached type list."); return typeList.Types; } @@ -673,7 +673,7 @@ namespace Umbraco.Core.Composing // so in this instance there will never be a result. if (cacheResult.Exception is CachedTypeNotFoundInFileException || cacheResult.Success == false) { - _logger.Logger.Debug("Getting {0}: failed to load from cache file, must scan assemblies.", () => GetName(baseType, attributeType)); + _logger.Logger.Debug(() => $"Getting {GetName(baseType, attributeType)}: failed to load from cache file, must scan assemblies."); scan = true; } else @@ -700,7 +700,7 @@ namespace Umbraco.Core.Composing if (scan == false) { - _logger.Logger.Debug("Getting {0}: loaded types from cache file.", () => GetName(baseType, attributeType)); + _logger.Logger.Debug(() => $"Getting {GetName(baseType, attributeType)}: loaded types from cache file."); } } } @@ -708,7 +708,7 @@ namespace Umbraco.Core.Composing if (scan) { // either we had to scan, or we could not get the types from the cache file - scan now - _logger.Logger.Debug("Getting {0}: scanning assemblies.", () => GetName(baseType, attributeType)); + _logger.Logger.Debug(() => $"Getting {GetName(baseType, attributeType)}: scanning assemblies."); foreach (var t in finder()) typeList.Add(t); @@ -726,11 +726,11 @@ namespace Umbraco.Core.Composing UpdateCache(); } - _logger.Logger.Debug("Got {0}, caching ({1}).", () => GetName(baseType, attributeType), () => added.ToString().ToLowerInvariant()); + _logger.Logger.Debug(() => $"Got {GetName(baseType, attributeType)}, caching ({added.ToString().ToLowerInvariant()})."); } else { - _logger.Logger.Debug("Got {0}.", () => GetName(baseType, attributeType)); + _logger.Logger.Debug(() => $"Got {GetName(baseType, attributeType)}."); } return typeList.Types; diff --git a/src/Umbraco.Core/Logging/ILogger.cs b/src/Umbraco.Core/Logging/ILogger.cs index f9514d5bb3..905ba9f7fa 100644 --- a/src/Umbraco.Core/Logging/ILogger.cs +++ b/src/Umbraco.Core/Logging/ILogger.cs @@ -32,14 +32,6 @@ namespace Umbraco.Core.Logging /// A message builder. void Warn(Type reporting, Func messageBuilder); - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation")] - void Warn(Type reporting, string format, params object[] args); - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation, if you want to use lazy generated strings use the overload with messageBuilder")] - void Warn(Type reporting, string format, params Func[] args); - /// /// Logs a warning message with an exception. /// @@ -56,14 +48,6 @@ namespace Umbraco.Core.Logging /// A message builder. void Warn(Type reporting, Exception exception, Func messageBuilder); - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation")] - void Warn(Type reporting, Exception exception, string format, params object[] args); - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation, if you want to use lazy generated strings use the overload with messageBuilder")] - void Warn(Type reporting, Exception exception, string format, params Func[] args); - /// /// Logs an information message. /// @@ -78,14 +62,6 @@ namespace Umbraco.Core.Logging /// A message builder. void Info(Type reporting, Func messageBuilder); - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation")] - void Info(Type reporting, string format, params object[] args); - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation, if you want to use lazy generated strings use the overload with messageBuilder")] - void Info(Type reporting, string format, params Func[] args); - /// /// Logs a debugging message. /// @@ -99,13 +75,5 @@ namespace Umbraco.Core.Logging /// The reporting type. /// A message builder. void Debug(Type reporting, Func messageBuilder); - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation")] - void Debug(Type reporting, string format, params object[] args); - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This method will be removed, do not use it, if you want to use formatting do it with string interpolation, if you want to use lazy generated strings use the overload with messageBuilder")] - void Debug(Type reporting, string format, params Func[] args); } } diff --git a/src/Umbraco.Core/Logging/LoggerExtensions.cs b/src/Umbraco.Core/Logging/LoggerExtensions.cs index 045709d03e..4c0a6b026a 100644 --- a/src/Umbraco.Core/Logging/LoggerExtensions.cs +++ b/src/Umbraco.Core/Logging/LoggerExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace Umbraco.Core.Logging { @@ -41,30 +42,6 @@ namespace Umbraco.Core.Logging logger.Warn(typeof(T), messageBuilder); } - /// - /// Logs a formatted warning message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of objects to format. - public static void Warn(this ILogger logger, string format, params object[] args) - { - logger.Warn(typeof(T), format, args); - } - - /// - /// Logs a formatted warning message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of functions returning objects to format. - public static void Warn(this ILogger logger, string format, params Func[] args) - { - logger.Warn(typeof(T), format, args); - } - /// /// Logs a formatted warning message with an exception. /// @@ -89,32 +66,6 @@ namespace Umbraco.Core.Logging logger.Warn(typeof(T), exception, message); } - /// - /// Logs a formatted warning message with an exception. - /// - /// The reporting type. - /// The logger. - /// An exception. - /// A composite format string. - /// An array of objects to format. - public static void Warn(this ILogger logger, Exception exception, string format, params object[] args) - { - logger.Warn(typeof(T), exception, format, args); - } - - /// - /// Logs a formatted warning message with an exception. - /// - /// The reporting type. - /// The logger. - /// An exception. - /// A composite format string. - /// An array of functions returning objects to format. - public static void Warn(this ILogger logger, Exception exception, string format, params Func[] args) - { - logger.Warn(typeof(T), exception, format, args); - } - /// /// Logs an information message. /// @@ -137,30 +88,6 @@ namespace Umbraco.Core.Logging logger.Info(typeof(T), messageBuilder); } - /// - /// Logs a formatted information message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of objects to format. - public static void Info(this ILogger logger, string format, params object[] args) - { - logger.Info(typeof(T), format, args); - } - - /// - /// Logs a formatted information message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of functions returning objects to format. - public static void Info(this ILogger logger, string format, params Func[] args) - { - logger.Info(typeof(T), format, args); - } - /// /// Logs a debugging message. /// @@ -182,29 +109,5 @@ namespace Umbraco.Core.Logging { logger.Debug(typeof(T), messageBuilder); } - - /// - /// Logs a formatted debugging message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of objects to format. - public static void Debug(this ILogger logger, string format, params object[] args) - { - logger.Debug(typeof(T), format, args); - } - - /// - /// Logs a formatted debugging message. - /// - /// The reporting type. - /// The logger. - /// A composite format string. - /// An array of functions returning objects to format. - public static void Debug(this ILogger logger, string format, params Func[] args) - { - logger.Debug(typeof(T), format, args); - } } } diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs index 452f9dc688..a4a4097e36 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs @@ -308,7 +308,7 @@ namespace Umbraco.Core.Migrations.Install { var source = connectionStrings.Attribute("configSource").Value; var configFile = IOHelper.MapPath($"{SystemDirectories.Root}/{source}"); - logger.Info("storing ConnectionString in {0}", () => configFile); + logger.Info($"Storing ConnectionString in {configFile}"); if (File.Exists(configFile)) { xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); diff --git a/src/Umbraco.Core/Migrations/MigrationPlan.cs b/src/Umbraco.Core/Migrations/MigrationPlan.cs index 733ff281e5..4ca900aecd 100644 --- a/src/Umbraco.Core/Migrations/MigrationPlan.cs +++ b/src/Umbraco.Core/Migrations/MigrationPlan.cs @@ -211,7 +211,7 @@ namespace Umbraco.Core.Migrations if (_migrationBuilder == null || _logger == null) throw new InvalidOperationException("Cannot execute a non-executing plan."); - _logger.Info("Starting \"{0}\"...", () => Name); + _logger.Info($"Starting \"{Name}\"..."); var origState = fromState ?? string.Empty; var info = "At " + (string.IsNullOrWhiteSpace(origState) ? "origin" : ("\"" + origState + "\"")) + "."; info = info.Replace("{", "{{").Replace("}", "}}"); // stupid log4net @@ -230,7 +230,7 @@ namespace Umbraco.Core.Migrations var nextState = transition.TargetState; origState = nextState; - _logger.Info("At \"{0}\".", origState); + _logger.Info($"At \"{origState}\"."); if (!_transitions.TryGetValue(origState, out transition)) throw new Exception($"Unknown state \"{origState}\"."); diff --git a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs index 885ef78263..4eccfe800f 100644 --- a/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs +++ b/src/Umbraco.Core/Persistence/DbConnectionExtensions.cs @@ -120,8 +120,7 @@ namespace Umbraco.Core.Persistence } catch (Exception ex) { - Current.Logger.Warn(typeof(DbConnectionExtensions), - "Could not resolve connection string parameters", ex); + Current.Logger.Warn(typeof(DbConnectionExtensions), ex, "Could not resolve connection string parameters"); return "(Could not resolve)"; } diff --git a/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs b/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs index 7cf1b48625..272d433f57 100644 --- a/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs +++ b/src/Umbraco.Core/Services/Implement/LocalizedTextService.cs @@ -104,7 +104,7 @@ namespace Umbraco.Core.Services.Implement { if (xmlSource.ContainsKey(culture) == false) { - _logger.Warn("The culture specified {0} was not found in any configured sources for this service", () => culture); + _logger.Warn(() => $"The culture specified {culture} was not found in any configured sources for this service"); return result; } @@ -124,7 +124,7 @@ namespace Umbraco.Core.Services.Implement { if (_dictionarySource.ContainsKey(culture) == false) { - _logger.Warn("The culture specified {0} was not found in any configured sources for this service", () => culture); + _logger.Warn(() => $"The culture specified {culture} was not found in any configured sources for this service"); return result; } @@ -224,7 +224,7 @@ namespace Umbraco.Core.Services.Implement { if (_dictionarySource.ContainsKey(culture) == false) { - _logger.Warn("The culture specified {0} was not found in any configured sources for this service", () => culture); + _logger.Warn(() => $"The culture specified {culture} was not found in any configured sources for this service"); return "[" + key + "]"; } @@ -262,7 +262,7 @@ namespace Umbraco.Core.Services.Implement { if (xmlSource.ContainsKey(culture) == false) { - _logger.Warn("The culture specified {0} was not found in any configured sources for this service", () => culture); + _logger.Warn(() => $"The culture specified {culture} was not found in any configured sources for this service"); return "[" + key + "]"; } diff --git a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs index cca2926a10..801d35d806 100644 --- a/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs +++ b/src/Umbraco.Core/Services/Implement/LocalizedTextServiceFileSources.cs @@ -126,7 +126,7 @@ namespace Umbraco.Core.Services.Implement if (fileSourceFolder.Exists == false) { - Current.Logger.Warn("The folder does not exist: {0}, therefore no sources will be discovered", () => fileSourceFolder.FullName); + Current.Logger.Warn(() => $"The folder does not exist: {fileSourceFolder.FullName}, therefore no sources will be discovered"); } else { diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 2bdad031de..f7d3b9a7a0 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -65,7 +65,7 @@ namespace Umbraco.Core.Sync protected IScopeProvider ScopeProvider { get; } protected Sql Sql() => _sqlContext.Sql(); - + private string DistCacheFilePath => _distCacheFilePath.Value; #region Messenger @@ -192,10 +192,9 @@ namespace Umbraco.Core.Sync if (count > Options.MaxProcessingInstructionCount) { //too many instructions, proceed to cold boot - Logger.Warn("The instruction count ({0}) exceeds the specified MaxProcessingInstructionCount ({1})." + Logger.Warn(() => $"The instruction count ({count}) exceeds the specified MaxProcessingInstructionCount ({Options.MaxProcessingInstructionCount})." + " The server will skip existing instructions, rebuild its caches and indexes entirely, adjust its last synced Id" - + " to the latest found in the database and maintain cache updates based on that Id.", - () => count, () => Options.MaxProcessingInstructionCount); + + " to the latest found in the database and maintain cache updates based on that Id."); coldboot = true; } diff --git a/src/Umbraco.Core/Sync/ServerMessengerBase.cs b/src/Umbraco.Core/Sync/ServerMessengerBase.cs index c021a64969..d16c88eca3 100644 --- a/src/Umbraco.Core/Sync/ServerMessengerBase.cs +++ b/src/Umbraco.Core/Sync/ServerMessengerBase.cs @@ -158,8 +158,7 @@ namespace Umbraco.Core.Sync { if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - Current.Logger.Debug("Invoking refresher {0} on local server for message type RefreshByPayload", - refresher.GetType); + Current.Logger.Debug(() => $"Invoking refresher {refresher.GetType()} on local server for message type RefreshByPayload"); var payloadRefresher = refresher as IPayloadCacheRefresher; if (payloadRefresher == null) @@ -181,9 +180,7 @@ namespace Umbraco.Core.Sync { if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - Current.Logger.Debug("Invoking refresher {0} on local server for message type {1}", - refresher.GetType, - () => messageType); + Current.Logger.Debug(() => $"Invoking refresher {refresher.GetType()} on local server for message type {messageType}"); switch (messageType) { @@ -244,9 +241,7 @@ namespace Umbraco.Core.Sync { if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - Current.Logger.Debug("Invoking refresher {0} on local server for message type {1}", - refresher.GetType, - () => messageType); + Current.Logger.Debug(() => $"Invoking refresher {refresher.GetType()} on local server for message type {messageType}"); var typedRefresher = refresher as ICacheRefresher; diff --git a/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs b/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs index 8025f36244..dff839fe6f 100644 --- a/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs +++ b/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs @@ -160,13 +160,8 @@ namespace Umbraco.Core.Sync Type idArrayType = null, string jsonPayload = null) { - Current.Logger.Debug( - "Performing distributed call for {0}/{1} on servers ({2}), ids: {3}, json: {4}", - refresher.GetType, - () => messageType, - () => string.Join(";", servers.Select(x => x.ToString())), - () => ids == null ? "" : string.Join(";", ids.Select(x => x.ToString())), - () => jsonPayload ?? ""); + Current.Logger.Debug(() => + $"Performing distributed call for {refresher.GetType()}/{messageType} on servers ({string.Join(";", servers.Select(x => x.ToString()))}), ids: {(ids == null ? "" : string.Join(";", ids.Select(x => x.ToString())))}, json: {(jsonPayload ?? "")}"); try { diff --git a/src/Umbraco.Examine/UmbracoExamineIndexer.cs b/src/Umbraco.Examine/UmbracoExamineIndexer.cs index be8ed55e01..f57ff07fa0 100644 --- a/src/Umbraco.Examine/UmbracoExamineIndexer.cs +++ b/src/Umbraco.Examine/UmbracoExamineIndexer.cs @@ -56,7 +56,7 @@ namespace Umbraco.Examine //This is using the config so we'll validate based on that ValueSetValidator = new ValueSetValidatorDelegate(set => { - + //check if this document is of a correct type of node type alias if (ConfigIndexCriteria.IncludeItemTypes.Any()) if (!ConfigIndexCriteria.IncludeItemTypes.Contains(set.ItemType)) @@ -72,7 +72,7 @@ namespace Umbraco.Examine } protected UmbracoExamineIndexer( - string name, + string name, IEnumerable fieldDefinitions, Directory luceneDirectory, Analyzer defaultAnalyzer, @@ -136,7 +136,7 @@ namespace Umbraco.Examine /// When set to true Umbraco will keep the index in sync with Umbraco data automatically /// public bool EnableDefaultEventHandler { get; set; } = true; - + /// /// the supported indexable types /// @@ -162,7 +162,7 @@ namespace Umbraco.Examine /// public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { - ProfilingLogger.Logger.Debug(GetType(), "{0} indexer initializing", () => name); + ProfilingLogger.Logger.Debug(GetType(), () => $"{name} indexer initializing"); if (config["enableDefaultEventHandler"] != null && bool.TryParse(config["enableDefaultEventHandler"], out var enabled)) { @@ -337,7 +337,7 @@ namespace Umbraco.Examine ProfilingLogger.Logger.Error(GetType(), e.Message, e.InnerException); base.OnIndexingError(e); } - + /// /// This ensures that the special __Raw_ fields are indexed /// @@ -359,20 +359,20 @@ namespace Umbraco.Examine } } - ProfilingLogger.Logger.Debug(GetType(), "Write lucene doc id:{0}, category:{1}, type:{2}", docArgs.ValueSet.Id, docArgs.ValueSet.Category, docArgs.ValueSet.ItemType); - + ProfilingLogger.Logger.Debug(GetType(), () => $"Write lucene doc id:{docArgs.ValueSet.Id}, category:{docArgs.ValueSet.Category}, type:{docArgs.ValueSet.ItemType}"); + base.OnDocumentWriting(docArgs); } /// /// Overridden for logging. - /// + /// protected override void AddDocument(Document doc, IndexItem item, IndexWriter writer) { - ProfilingLogger.Logger.Debug(GetType(), "AddDocument {0} with type {1}", () => item.ValueSet.Id, () => item.ValueSet.ItemType); + ProfilingLogger.Logger.Debug(GetType(), () => $"AddDocument {item.ValueSet.Id} with type {item.ValueSet.ItemType}"); base.AddDocument(doc, item, writer); } - + protected override void OnTransformingIndexValues(IndexingItemEventArgs e) { base.OnTransformingIndexValues(e); diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index e15c371d20..42382eacdd 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -405,22 +405,19 @@ namespace Umbraco.Web.Editors if (lockedOut) { Logger.Info( - "User {0} is currently locked out, unlocking and resetting AccessFailedCount", - () => model.UserId); + $"User {model.UserId} is currently locked out, unlocking and resetting AccessFailedCount"); //var user = await UserManager.FindByIdAsync(model.UserId); var unlockResult = await UserManager.SetLockoutEndDateAsync(model.UserId, DateTimeOffset.Now); if (unlockResult.Succeeded == false) { - Logger.Warn("Could not unlock for user {0} - error {1}", - () => model.UserId, () => unlockResult.Errors.First()); + Logger.Warn(() => $"Could not unlock for user {model.UserId} - error {unlockResult.Errors.First()}"); } var resetAccessFailedCountResult = await UserManager.ResetAccessFailedCountAsync(model.UserId); if (resetAccessFailedCountResult.Succeeded == false) { - Logger.Warn("Could not reset access failed count {0} - error {1}", - () => model.UserId, () => unlockResult.Errors.First()); + Logger.Warn(() => $"Could not reset access failed count {model.UserId} - error {unlockResult.Errors.First()}"); } } @@ -446,9 +443,7 @@ namespace Umbraco.Web.Editors Core.Constants.Security.BackOfficeAuthenticationType, Core.Constants.Security.BackOfficeExternalAuthenticationType); - Logger.Info("User {0} from IP address {1} has logged out", - () => User.Identity == null ? "UNKNOWN" : User.Identity.Name, - () => owinContext.Request.RemoteIpAddress); + Logger.Info($"User {(User.Identity == null ? "UNKNOWN" : User.Identity.Name)} from IP address {owinContext.Request.RemoteIpAddress} has logged out"); if (UserManager != null) { diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 10a05069e9..0aa43c8cfb 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -185,10 +185,7 @@ namespace Umbraco.Web.Editors var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(ctSave.Alias, ctSave.Name); if (tryCreateTemplate == false) { - Logger.Warn( - "Could not create a template for the Content Type: {0}, status: {1}", - () => ctSave.Alias, - () => tryCreateTemplate.Result.Result); + Logger.Warn(() => $"Could not create a template for the Content Type: {ctSave.Alias}, status: {tryCreateTemplate.Result.Result}"); } template = tryCreateTemplate.Result.Entity; } diff --git a/src/Umbraco.Web/Editors/PackageInstallController.cs b/src/Umbraco.Web/Editors/PackageInstallController.cs index 46e35f511d..1564ed47cf 100644 --- a/src/Umbraco.Web/Editors/PackageInstallController.cs +++ b/src/Umbraco.Web/Editors/PackageInstallController.cs @@ -194,7 +194,7 @@ namespace Umbraco.Web.Editors var actionsXml = new XmlDocument(); actionsXml.LoadXml("" + pack.Data.Actions + ""); - Logger.Debug("executing undo actions: {0}", () => actionsXml.OuterXml); + Logger.Debug(() => $"executing undo actions: {actionsXml.OuterXml}"); foreach (XmlNode n in actionsXml.DocumentElement.SelectNodes("//Action")) { diff --git a/src/Umbraco.Web/Editors/PasswordChanger.cs b/src/Umbraco.Web/Editors/PasswordChanger.cs index 1343d7cacd..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("Could not reset member password", ex); + _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("Could not change member password", ex); + _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("Could not change member password", ex); + _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("Could not change member password", ex1); + _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("Could not retrieve member password", ex2); + _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/Install/InstallSteps/Version73FileCleanup.cs b/src/Umbraco.Web/Install/InstallSteps/Version73FileCleanup.cs index 289fdda078..57f393b58a 100644 --- a/src/Umbraco.Web/Install/InstallSteps/Version73FileCleanup.cs +++ b/src/Umbraco.Web/Install/InstallSteps/Version73FileCleanup.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web.Install.InstallSteps var dll = bin[0].GetFiles("Microsoft.Web.Mvc.FixedDisplayModes.dll", SearchOption.TopDirectoryOnly); if (dll.Length == 1) { - _logger.Info("Deleting non-compatible and no longer used DLL: {0}", () => dll[0].FullName); + _logger.Info($"Deleting non-compatible and no longer used DLL: {dll[0].FullName}"); File.Delete(dll[0].FullName); } } @@ -70,7 +70,7 @@ namespace Umbraco.Web.Install.InstallSteps foreach (var configFile in found) { var fileName = configFile.FullName; - _logger.Info("Cleaning up web.config file: {0}", () => fileName); + _logger.Info($"Cleaning up web.config file: {fileName}"); var contents = File.ReadAllText(fileName); contents = _microsoftWebHelpers.Replace(contents, string.Empty); diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 5b7c14ac05..974c9509a3 100644 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -101,7 +101,7 @@ namespace Umbraco.Web.Macros if (macroContent == null) return null; - Current.Logger.Debug("Macro content loaded from cache \"{0}\".", () => model.CacheIdentifier); + Current.Logger.Debug(() => $"Macro content loaded from cache \"{model.CacheIdentifier}\"."); // ensure that the source has not changed // note: does not handle dependencies, and never has @@ -166,7 +166,7 @@ namespace Umbraco.Web.Macros priority: CacheItemPriority.NotRemovable ); - Current.Logger.Debug("Macro content saved to cache \"{0}\".", () => model.CacheIdentifier); + Current.Logger.Debug(() => $"Macro content saved to cache \"{model.CacheIdentifier}\"."); } // gets the macro source file name diff --git a/src/Umbraco.Web/Migrations/OverwriteStylesheetFilesFromTempFiles.cs b/src/Umbraco.Web/Migrations/OverwriteStylesheetFilesFromTempFiles.cs index 380636c876..88c4972517 100644 --- a/src/Umbraco.Web/Migrations/OverwriteStylesheetFilesFromTempFiles.cs +++ b/src/Umbraco.Web/Migrations/OverwriteStylesheetFilesFromTempFiles.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.Migrations { //backup var targetPath = Path.Combine(tempCssFolder, relativePath.EnsureEndsWith(".bak")); - logger.Info("CSS file is being backed up from {0}, to {1} before being migrated to new format", () => cssFilePath, () => targetPath); + logger.Info($"CSS file is being backed up from {cssFilePath}, to {targetPath} before being migrated to new format"); File.Copy(cssFilePath, targetPath, true); } diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 71fca39eb0..3b0b6b35e2 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -319,12 +319,8 @@ namespace Umbraco.Web.Mvc } else { - Current.Logger.Warn( - "The current Document Type {0} matches a locally declared controller of type {1}. Custom Controllers for Umbraco routing must implement '{2}' and inherit from '{3}'.", - () => request.PublishedContent.DocumentTypeAlias, - () => controllerType.FullName, - () => typeof(IRenderController).FullName, - () => typeof(ControllerBase).FullName); + Current.Logger.Warn(() => + $"The current Document Type {request.PublishedContent.DocumentTypeAlias} matches a locally declared controller of type {controllerType.FullName}. Custom Controllers for Umbraco routing must implement '{typeof(IRenderController).FullName}' and inherit from '{typeof(ControllerBase).FullName}'."); //we cannot route to this custom controller since it is not of the correct type so we'll continue with the defaults // that have already been set above. diff --git a/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs b/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs index 675b3e4d24..c846e0e863 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs @@ -70,7 +70,7 @@ namespace Umbraco.Web.PublishedCache /// An identifier. public void ClearContentType(int id) { - _logger.Debug("Clear content type w/id {0}.", () => id); + _logger.Debug(() => $"Clear content type w/id {id}."); try { @@ -105,7 +105,7 @@ namespace Umbraco.Web.PublishedCache /// A data type identifier. public void ClearDataType(int id) { - _logger.Debug("Clear data type w/id {0}.", () => id); + _logger.Debug(() => $"Clear data type w/id {id}."); // there is no recursion to handle here because a PublishedContentType contains *all* its // properties ie both its own properties and those that were inherited (it's based upon an diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index 5391c890a3..fc8afe4939 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -232,7 +232,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache return null; } } - + private ISearcher GetSearchProviderSafe() { if (_searchProvider != null) @@ -333,9 +333,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache var miss = Interlocked.CompareExchange(ref _examineIndexMiss, 0, 0); // volatile read if (miss < ExamineIndexMissMax && Interlocked.Increment(ref _examineIndexMiss) == ExamineIndexMissMax) - Current.Logger.Warn("Failed ({0} times) to retrieve medias from Examine index and had to load" - + " them from DB. This may indicate that the Examine index is corrupted.", - () => ExamineIndexMissMax); + Current.Logger.Warn(() => $"Failed ({ExamineIndexMissMax} times) to retrieve medias from Examine index and had to load" + + " them from DB. This may indicate that the Examine index is corrupted."); return ConvertFromIMedia(media); } @@ -352,9 +351,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache : ConvertFromXPathNavigator(media.Current); } - Current.Logger.Warn( - "Could not retrieve media {0} from Examine index or from legacy library.GetMedia method", - () => id); + Current.Logger.Warn(() => + $"Could not retrieve media {id} from Examine index or from legacy library.GetMedia method"); return null; } @@ -362,7 +360,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache internal CacheValues ConvertFromSearchResult(SearchResult searchResult) { // note: fixing fields in 7.x, removed by Shan for 8.0 - + return new CacheValues { Values = searchResult.Fields, diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStoreFilePersister.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStoreFilePersister.cs index 8a68812d4d..6b247bdf0d 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStoreFilePersister.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlStoreFilePersister.cs @@ -62,7 +62,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (touched == false) return; - _logger.Debug("Created, save in {0}ms.", () => WaitMilliseconds); + _logger.Debug(() => $"Created, save in {WaitMilliseconds}ms."); _initialTouch = DateTime.Now; _timer = new Timer(_ => TimerRelease()); _timer.Change(WaitMilliseconds, 0); @@ -107,7 +107,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache else if (_timer == null) // we don't have a timer yet { - _logger.Debug("Touched, was idle, start and save in {0}ms.", () => WaitMilliseconds); + _logger.Debug(() => $"Touched, was idle, start and save in {WaitMilliseconds}ms."); _initialTouch = DateTime.Now; _timer = new Timer(_ => TimerRelease()); _timer.Change(WaitMilliseconds, 0); @@ -120,7 +120,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (DateTime.Now - _initialTouch < TimeSpan.FromMilliseconds(MaxWaitMilliseconds)) { - _logger.Debug("Touched, was waiting, can delay, save in {0}ms.", () => WaitMilliseconds); + _logger.Debug(() => $"Touched, was waiting, can delay, save in {WaitMilliseconds}ms."); _timer.Change(WaitMilliseconds, 0); } else diff --git a/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs index 4257d61203..eb3e481a7b 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByIdPath.cs @@ -53,13 +53,13 @@ namespace Umbraco.Web.Routing if (nodeId > 0) { - _logger.Debug("Id={0}", () => nodeId); + _logger.Debug(() => $"Id={nodeId}"); node = frequest.UmbracoContext.ContentCache.GetById(nodeId); if (node != null) { frequest.PublishedContent = node; - _logger.Debug("Found node with id={0}", () => frequest.PublishedContent.Id); + _logger.Debug(() => $"Found node with id={frequest.PublishedContent.Id}"); } else { diff --git a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs index 77144bcdb1..a687d43dbe 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs @@ -70,7 +70,7 @@ namespace Umbraco.Web.Routing if (error404.HasValue) { - _logger.Debug("Got id={0}.", () => error404.Value); + _logger.Debug(() => $"Got id={error404.Value}."); content = frequest.UmbracoContext.ContentCache.GetById(error404.Value); diff --git a/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs b/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs index b4d36e66e9..094c0addaf 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs @@ -44,13 +44,13 @@ namespace Umbraco.Web.Routing /// The document node, or null. protected IPublishedContent FindContent(PublishedRequest docreq, string route) { - Logger.Debug("Test route \"{0}\"", () => route); + Logger.Debug(() => $"Test route \"{route}\""); var node = docreq.UmbracoContext.ContentCache.GetByRoute(route); if (node != null) { docreq.PublishedContent = node; - Logger.Debug("Got content, id={0}", () => node.Id); + Logger.Debug(() => $"Got content, id={node.Id}"); } else { diff --git a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs index e0d21f0fa8..d0eaa55b79 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Routing var template = Current.Services.FileService.GetTemplate(templateAlias); if (template != null) { - Logger.Debug("Valid template: \"{0}\"", () => templateAlias); + Logger.Debug(() => $"Valid template: \"{templateAlias}\""); var route = frequest.HasDomain ? (frequest.Domain.ContentId.ToString() + path) : path; node = FindContent(frequest, route); @@ -53,7 +53,7 @@ namespace Umbraco.Web.Routing } else { - Logger.Debug("Not a valid template: \"{0}\"", () => templateAlias); + Logger.Debug(() => $"Not a valid template: \"{templateAlias}\""); } } else diff --git a/src/Umbraco.Web/Routing/ContentFinderByProfile.cs b/src/Umbraco.Web/Routing/ContentFinderByProfile.cs index 42507c7cda..6abc663dbc 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByProfile.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByProfile.cs @@ -39,7 +39,7 @@ namespace Umbraco.Web.Routing if (path == GlobalSettings.ProfileUrl) { isProfile = true; - Logger.Debug("Path \"{0}\" is the profile path", () => path); + Logger.Debug(() => $"Path \"{path}\" is the profile path"); var route = frequest.HasDomain ? (frequest.Domain.ContentId + path) : path; node = FindContent(frequest, route); diff --git a/src/Umbraco.Web/Routing/ContentFinderByRedirectUrl.cs b/src/Umbraco.Web/Routing/ContentFinderByRedirectUrl.cs index f79293186d..b8bc5f19fb 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByRedirectUrl.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByRedirectUrl.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.Routing if (redirectUrl == null) { - _logger.Debug("No match for route: \"{0}\".", () => route); + _logger.Debug(() => $"No match for route: \"{route}\"."); return false; } @@ -56,13 +56,11 @@ namespace Umbraco.Web.Routing var url = content == null ? "#" : content.Url; if (url.StartsWith("#")) { - _logger.Debug("Route \"{0}\" matches content {1} which has no url.", - () => route, () => redirectUrl.ContentId); + _logger.Debug(() => $"Route \"{route}\" matches content {redirectUrl.ContentId} which has no url."); return false; } - _logger.Debug("Route \"{0}\" matches content {1} with url \"{2}\", redirecting.", - () => route, () => content.Id, () => url); + _logger.Debug(() => $"Route \"{route}\" matches content {content.Id} with url \"{url}\", redirecting."); frequest.SetRedirectPermanent(url); return true; } diff --git a/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs b/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs index 0408055710..1117a57592 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Routing if (node != null) { frequest.PublishedContent = node; - Logger.Debug("Path \"{0}\" is an alias for id={1}", () => frequest.Uri.AbsolutePath, () => frequest.PublishedContent.Id); + Logger.Debug(() => $"Path \"{frequest.Uri.AbsolutePath}\" is an alias for id={frequest.PublishedContent.Id}"); } } diff --git a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs index 087fd12dad..359e5bfcad 100644 --- a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs @@ -49,9 +49,8 @@ namespace Umbraco.Web.Routing { if (string.IsNullOrWhiteSpace(route)) { - _logger.Debug( - "Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.", - () => id); + _logger.Debug(() => + $"Couldn't find any page with nodeId={id}. This is most likely caused by the page not being published."); return null; } @@ -91,9 +90,8 @@ namespace Umbraco.Web.Routing if (string.IsNullOrWhiteSpace(route)) { - _logger.Debug( - "Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.", - () => id); + _logger.Debug(() => + $"Couldn't find any page with nodeId={id}. This is most likely caused by the page not being published."); return null; } diff --git a/src/Umbraco.Web/Routing/PublishedRouter.cs b/src/Umbraco.Web/Routing/PublishedRouter.cs index 5f832fd97a..ac07f1ad32 100644 --- a/src/Umbraco.Web/Routing/PublishedRouter.cs +++ b/src/Umbraco.Web/Routing/PublishedRouter.cs @@ -263,7 +263,7 @@ namespace Umbraco.Web.Routing // note - we are not handling schemes nor ports here. - _logger.Debug("{0}Uri=\"{1}\"", () => tracePrefix, () => request.Uri); + _logger.Debug(() => $"{tracePrefix}Uri=\"{request.Uri}\""); // try to find a domain matching the current request var domainAndUri = DomainHelper.DomainForUri(request.UmbracoContext.PublishedShapshot.Domains.GetAll(false), request.Uri); @@ -272,11 +272,7 @@ namespace Umbraco.Web.Routing if (domainAndUri != null) { // matching an existing domain - _logger.Debug("{0}Matches domain=\"{1}\", rootId={2}, culture=\"{3}\"", - () => tracePrefix, - () => domainAndUri.Name, - () => domainAndUri.ContentId, - () => domainAndUri.Culture); + _logger.Debug(() => $"{tracePrefix}Matches domain=\"{domainAndUri.Name}\", rootId={domainAndUri.ContentId}, culture=\"{domainAndUri.Culture}\""); request.Domain = domainAndUri; request.Culture = domainAndUri.Culture; @@ -291,13 +287,13 @@ namespace Umbraco.Web.Routing else { // not matching any existing domain - _logger.Debug("{0}Matches no domain", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Matches no domain"); var defaultLanguage = _services.LocalizationService.GetAllLanguages().FirstOrDefault(); request.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode); } - _logger.Debug("{0}Culture=\"{1}\"", () => tracePrefix, () => request.Culture.Name); + _logger.Debug(() => $"{tracePrefix}Culture=\"{request.Culture.Name}\""); return request.Domain != null; } @@ -313,7 +309,7 @@ namespace Umbraco.Web.Routing return; var nodePath = request.PublishedContent.Path; - _logger.Debug("{0}Path=\"{1}\"", () => tracePrefix, () => nodePath); + _logger.Debug(() => $"{tracePrefix}Path=\"{nodePath}\""); var rootNodeId = request.HasDomain ? request.Domain.ContentId : (int?)null; var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedShapshot.Domains.GetAll(true), nodePath, rootNodeId); @@ -321,12 +317,11 @@ namespace Umbraco.Web.Routing if (domain != null) { request.Culture = domain.Culture; - _logger.Debug("{0}Got domain on node {1}, set culture to \"{2}\".", () => tracePrefix, - () => domain.ContentId, () => request.Culture.Name); + _logger.Debug(() => $"{tracePrefix}Got domain on node {domain.ContentId}, set culture to \"{request.Culture.Name}\"."); } else { - _logger.Debug("{0}No match.", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}No match."); } } @@ -400,7 +395,7 @@ namespace Umbraco.Web.Routing private void FindPublishedContentAndTemplate(PublishedRequest request) { const string tracePrefix = "FindPublishedContentAndTemplate: "; - _logger.Debug("{0}Path=\"{1}\"", () => tracePrefix, () => request.Uri.AbsolutePath); + _logger.Debug(() => $"{tracePrefix}Path=\"{request.Uri.AbsolutePath}\""); // run the document finders FindPublishedContent(request); @@ -469,22 +464,22 @@ namespace Umbraco.Web.Routing const int maxLoop = 8; do { - _logger.Debug("{0}{1}", () => tracePrefix, () => (i == 0 ? "Begin" : "Loop")); + _logger.Debug(() => $"{tracePrefix}{(i == 0 ? "Begin" : "Loop")}"); // handle not found if (request.HasPublishedContent == false) { request.Is404 = true; - _logger.Debug("{0}No document, try last chance lookup", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}No document, try last chance lookup"); // if it fails then give up, there isn't much more that we can do if (_contentLastChanceFinder.TryFindContent(request) == false) { - _logger.Debug("{0}Failed to find a document, give up", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Failed to find a document, give up"); break; } - _logger.Debug("{0}Found a document", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Found a document"); } // follow internal redirects as long as it's not running out of control ie infinite loop of some sort @@ -506,11 +501,11 @@ namespace Umbraco.Web.Routing if (i == maxLoop || j == maxLoop) { - _logger.Debug("{0}Looks like we're running into an infinite loop, abort", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Looks like we're running into an infinite loop, abort"); request.PublishedContent = null; } - _logger.Debug("{0}End", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}End"); } /// @@ -596,13 +591,13 @@ namespace Umbraco.Web.Routing if (publicAccessAttempt) { - _logger.Debug("{0}Page is protected, check for access", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Page is protected, check for access"); var membershipHelper = new MembershipHelper(request.UmbracoContext); if (membershipHelper.IsLoggedIn() == false) { - _logger.Debug("{0}Not logged in, redirect to login page", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Not logged in, redirect to login page"); var loginPageId = publicAccessAttempt.Result.LoginNodeId; @@ -611,19 +606,19 @@ namespace Umbraco.Web.Routing } else if (_services.PublicAccessService.HasAccess(request.PublishedContent.Id, _services.ContentService, GetRolesForLogin(membershipHelper.CurrentUserName)) == false) { - _logger.Debug("{0}Current member has not access, redirect to error page", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Current member has not access, redirect to error page"); var errorPageId = publicAccessAttempt.Result.NoAccessNodeId; if (errorPageId != request.PublishedContent.Id) request.PublishedContent = request.UmbracoContext.PublishedShapshot.Content.GetById(errorPageId); } else { - _logger.Debug("{0}Current member has access", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Current member has access"); } } else { - _logger.Debug("{0}Page is not protected", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}Page is not protected"); } } @@ -663,7 +658,7 @@ namespace Umbraco.Web.Routing if (request.HasTemplate) { - _logger.Debug("{0}Has a template already, and no alternate template.", () => tracePrefix); + _logger.Debug("{0}Has a template already, and no alternate template."); return; } @@ -674,16 +669,16 @@ namespace Umbraco.Web.Routing if (templateId > 0) { - _logger.Debug("{0}Look for template id={1}", () => tracePrefix, () => templateId); + _logger.Debug(() => $"{tracePrefix}Look for template id={templateId}"); var template = _services.FileService.GetTemplate(templateId); if (template == null) throw new InvalidOperationException("The template with Id " + templateId + " does not exist, the page cannot render"); request.TemplateModel = template; - _logger.Debug("{0}Got template id={1} alias=\"{2}\"", () => tracePrefix, () => template.Id, () => template.Alias); + _logger.Debug(() => $"{tracePrefix}Got template id={template.Id} alias=\"{template.Alias}\""); } else { - _logger.Debug("{0}No specified template.", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}No specified template."); } } else @@ -695,24 +690,24 @@ namespace Umbraco.Web.Routing // ignore if the alias does not match - just trace if (request.HasTemplate) - _logger.Debug("{0}Has a template already, but also an alternate template.", () => tracePrefix); - _logger.Debug("{0}Look for alternate template alias=\"{1}\"", () => tracePrefix, () => altTemplate); + _logger.Debug(() => $"{tracePrefix}Has a template already, but also an alternate template."); + _logger.Debug(() => $"{tracePrefix}Look for alternate template alias=\"{altTemplate}\""); var template = _services.FileService.GetTemplate(altTemplate); if (template != null) { request.TemplateModel = template; - _logger.Debug("{0}Got template id={1} alias=\"{2}\"", () => tracePrefix, () => template.Id, () => template.Alias); + _logger.Debug(() => $"{tracePrefix}Got template id={template.Id} alias=\"{template.Alias}\""); } else { - _logger.Debug("{0}The template with alias=\"{1}\" does not exist, ignoring.", () => tracePrefix, () => altTemplate); + _logger.Debug(() => $"{tracePrefix}The template with alias=\"{altTemplate}\" does not exist, ignoring."); } } if (request.HasTemplate == false) { - _logger.Debug("{0}No template was found.", () => tracePrefix); + _logger.Debug(() => $"{tracePrefix}No template was found."); // initial idea was: if we're not already 404 and UmbracoSettings.HandleMissingTemplateAs404 is true // then reset _pcr.Document to null to force a 404. @@ -725,7 +720,7 @@ namespace Umbraco.Web.Routing } else { - _logger.Debug("{0}Running with template id={1} alias=\"{2}\"", () => tracePrefix, () => request.TemplateModel.Id, () => request.TemplateModel.Alias); + _logger.Debug(() => $"{tracePrefix}Running with template id={request.TemplateModel.Id} alias=\"{request.TemplateModel.Alias}\""); } } diff --git a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs index a95d0a2ae7..7516026852 100644 --- a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs +++ b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs @@ -233,7 +233,7 @@ namespace Umbraco.Web.Scheduling throw new InvalidOperationException("The task runner has completed."); // add task - _logger.Debug(_logPrefix + "Task added {0}", () => task.GetType().FullName); + _logger.Debug(() => _logPrefix + "Task added " + task.GetType().FullName); _tasks.Post(task); // start @@ -253,12 +253,12 @@ namespace Umbraco.Web.Scheduling { if (_completed) { - _logger.Debug(_logPrefix + "Task cannot be added {0}, the task runner has already shutdown", () => task.GetType().FullName); + _logger.Debug(() => _logPrefix + $"Task cannot be added {task.GetType().FullName}, the task runner has already shutdown"); return false; } // add task - _logger.Debug(_logPrefix + "Task added {0}", () => task.GetType().FullName); + _logger.Debug(() => _logPrefix + "Task added " + task.GetType().FullName); _tasks.Post(task); // start diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 7f42eafb9c..b1709259c4 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -341,9 +341,7 @@ namespace Umbraco.Web var end = false; var response = context.Response; - logger.Debug("Response status: Redirect={0}, Is404={1}, StatusCode={2}", - () => pcr.IsRedirect ? (pcr.IsRedirectPermanent ? "permanent" : "redirect") : "none", - () => pcr.Is404 ? "true" : "false", () => pcr.ResponseStatusCode); + logger.Debug(() => $"Response status: Redirect={(pcr.IsRedirect ? (pcr.IsRedirectPermanent ? "permanent" : "redirect") : "none")}, Is404={(pcr.Is404 ? "true" : "false")}, StatusCode={pcr.ResponseStatusCode}"); if(pcr.Cacheability != default(HttpCacheability)) response.Cache.SetCacheability(pcr.Cacheability); @@ -540,7 +538,7 @@ namespace Umbraco.Web app.BeginRequest += (sender, e) => { var httpContext = ((HttpApplication) sender).Context; - Logger.Debug("Begin request: {0}.", () => httpContext.Request.Url); + Logger.Debug(() => $"Begin request: {httpContext.Request.Url}."); BeginRequest(new HttpContextWrapper(httpContext)); }; diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 0e24f2bbd8..d85fce59cd 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -275,7 +275,7 @@ namespace umbraco Current.Logger.Error("An error occurred looking up media", ex); } - Current.Logger.Debug("No media result for id {0}", () => MediaId); + Current.Logger.Debug(() => $"No media result for id {MediaId}"); var errorXml = new XElement("error", string.Format("No media is maching '{0}'", MediaId)); return errorXml.CreateNavigator().Select("/"); @@ -331,7 +331,7 @@ namespace umbraco Current.Logger.Error("An error occurred looking up member", ex); } - Current.Logger.Debug("No member result for id {0}", () => MemberId); + Current.Logger.Debug(() => $"No member result for id {MemberId}"); var xd = new XmlDocument(); xd.LoadXml(string.Format("No member is maching '{0}'", MemberId)); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs index 0488589e7b..c10c35a6c0 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs @@ -34,11 +34,8 @@ namespace umbraco.presentation.webservices if (string.IsNullOrEmpty(hash)) return false; // no hash = don't know = not self if (hash != WebServiceServerMessenger.GetCurrentServerHash()) return false; - Current.Logger.Debug( - "Ignoring self-message. (server: {0}, appId: {1}, hash: {2})", - () => NetworkHelper.MachineName, - () => HttpRuntime.AppDomainAppId, - () => hash); + Current.Logger.Debug(() => + $"Ignoring self-message. (server: {NetworkHelper.MachineName}, appId: {HttpRuntime.AppDomainAppId}, hash: {hash})"); return true; }