diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/ModeMatchResult.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/ModeMatchResult.cs index a8892cbe3b..efdd9b399a 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/ModeMatchResult.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/ModeMatchResult.cs @@ -55,13 +55,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal attribute => PartiallyMatchedAttributes.Contains( attribute, StringComparer.OrdinalIgnoreCase))); - logger.LogWarning(new PartialModeMatchLoggerStructure(uniqueId, viewPath, partialOnlyMatches)); + logger.LogWarning(new PartialModeMatchLogValues(uniqueId, viewPath, partialOnlyMatches)); } if (logger.IsEnabled(LogLevel.Verbose) && !FullMatches.Any()) { - logger.LogVerbose("Skipping processing for {0} {1}", - tagHelper.GetType().GetTypeInfo().FullName, uniqueId); + logger.LogVerbose( + "Skipping processing for tag helper '{TagHelper}' with id '{TagHelperId}'.", + tagHelper.GetType().GetTypeInfo().FullName, + uniqueId); } } } diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialAttributeLoggerStructureOfT.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLogValuesOfT.cs similarity index 63% rename from src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialAttributeLoggerStructureOfT.cs rename to src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLogValuesOfT.cs index 74c1acaf01..e1b2225001 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialAttributeLoggerStructureOfT.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLogValuesOfT.cs @@ -11,49 +11,50 @@ using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.TagHelpers.Internal { /// - /// An for log messages regarding instances that opt out of + /// Log values for instances that opt out of /// processing due to missing attributes for one of several possible modes. /// - public class PartialModeMatchLoggerStructure : PartialModeMatchLoggerStructure + public class PartialModeMatchLogValues : ILogValues { private readonly string _uniqueId; private readonly string _viewPath; private readonly IEnumerable> _partialMatches; /// - /// Creates a new . + /// Creates a new . /// /// The unique ID of the HTML element this message applies to. /// The path to the view. /// The set of modes with partial required attributes. - public PartialModeMatchLoggerStructure( + public PartialModeMatchLogValues( string uniqueId, string viewPath, [NotNull] IEnumerable> partialMatches) - : base(values: new Dictionary - { - ["UniqueId"] = uniqueId, - ["ViewPath"] = viewPath, - ["PartialMatches"] = partialMatches - }) { _uniqueId = uniqueId; _viewPath = viewPath; _partialMatches = partialMatches; } - - /// - /// Generates a human readable string for this structured log message. - /// - /// The message. - public override string Format() + + public override string ToString() { var newLine = Environment.NewLine; return string.Format( - $"Tag Helper with ID {_uniqueId} in view '{_viewPath}' had partial matches while determining mode:{newLine}\t{{0}}", + $"Tag Helper with ID '{_uniqueId}' in view '{_viewPath}' had partial matches " + + $"while determining mode:{newLine}\t{{0}}", string.Join($"{newLine}\t", _partialMatches.Select(partial => string.Format($"Mode '{partial.Mode}' missing attributes:{newLine}\t\t{{0}} ", string.Join($"{newLine}\t\t", partial.MissingAttributes))))); } + + public IEnumerable> GetValues() + { + yield return new KeyValuePair( + "Message", + "Tag helper had partial matches while determining mode."); + yield return new KeyValuePair("UniqueId", _uniqueId); + yield return new KeyValuePair("ViewPath", _viewPath); + yield return new KeyValuePair("PartialMatches", _partialMatches); + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLoggerStructure.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLoggerStructure.cs deleted file mode 100644 index df7f4d166e..0000000000 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/PartialModeMatchLoggerStructure.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.Framework.Logging; - -namespace Microsoft.AspNet.Mvc.TagHelpers.Internal -{ - /// - /// An for log messages regarding instances that opt out of - /// processing due to missing attributes for one of several possible modes. - /// - public abstract class PartialModeMatchLoggerStructure : ILogValues - { - private readonly IEnumerable> _values; - - protected PartialModeMatchLoggerStructure(IEnumerable> values) - { - _values = values; - } - - /// - /// The log message. - /// - public string Message - { - get - { - return "Tag Helper has missing required attributes."; - } - } - - /// - /// Returns a human-readable string of the structured data. - /// - public abstract string Format(); - - /// - /// Gets the values associated with this structured log message. - /// - /// The values. - public IEnumerable> GetValues() - { - return _values; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs index caf69579a7..2102882e59 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs @@ -182,11 +182,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [Activate] [HtmlAttributeNotBound] - public ILoggerFactory LoggerFactory { get; set; } - - // TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed - [HtmlAttributeNotBound] - public ILogger Logger { get; set; } + protected internal ILogger Logger { get; set; } [Activate] [HtmlAttributeNotBound] @@ -222,9 +218,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails); - var logger = Logger ?? LoggerFactory.CreateLogger(); - - modeResult.LogDetails(logger, this, context.UniqueId, ViewContext.View.Path); + modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path); if (!modeResult.FullMatches.Any()) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs index d6e767285d..5dfbbcf01e 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs @@ -151,11 +151,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [Activate] [HtmlAttributeNotBound] - public ILoggerFactory LoggerFactory { get; set; } - - // TODO: will remove LoggerFactory and activate logger once DI/hosting bug is fixed - [HtmlAttributeNotBound] - public ILogger Logger { get; set; } + protected internal ILogger Logger { get; set; } [Activate] [HtmlAttributeNotBound] @@ -191,9 +187,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails); - var logger = Logger ?? LoggerFactory.CreateLogger(); - - modeResult.LogDetails(logger, this, context.UniqueId, ViewContext.View.Path); + modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path); if (!modeResult.FullMatches.Any()) { diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs index a5423a1a0a..03ff8a49ad 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs @@ -411,13 +411,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers Assert.Equal(2, logger.Logged.Count); Assert.Equal(LogLevel.Warning, logger.Logged[0].LogLevel); - Assert.IsAssignableFrom(logger.Logged[0].State); + Assert.IsAssignableFrom(logger.Logged[0].State); - var loggerData0 = (PartialModeMatchLoggerStructure)logger.Logged[0].State; + var loggerData0 = (ILogValues)logger.Logged[0].State; Assert.Equal(LogLevel.Verbose, logger.Logged[1].LogLevel); Assert.IsAssignableFrom(logger.Logged[1].State); - Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper", + Assert.StartsWith("Skipping processing for tag helper 'Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper'" + + " with id", ((ILogValues)logger.Logged[1].State).ToString()); } @@ -472,7 +473,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers Assert.Equal(LogLevel.Verbose, logger.Logged[0].LogLevel); Assert.IsAssignableFrom(logger.Logged[0].State); - Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper", + Assert.StartsWith("Skipping processing for tag helper 'Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper'", ((ILogValues)logger.Logged[0].State).ToString()); }