diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs index 80b2a3f688..26d1b859cf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -368,7 +369,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _redirectToRouteResultExecuting(logger, destination, routeName, null); } - private class ActionLogScope : ILogValues + private class ActionLogScope : IReadOnlyList> { private readonly ActionDescriptor _action; @@ -382,13 +383,36 @@ namespace Microsoft.AspNetCore.Mvc.Internal _action = action; } - public IEnumerable> GetValues() + public KeyValuePair this[int index] { - return new KeyValuePair[] + get { - new KeyValuePair("ActionId", _action.Id), - new KeyValuePair("ActionName", _action.DisplayName), - }; + if (index == 0) + { + return new KeyValuePair("ActionId", _action.Id); + } + else if (index == 1) + { + return new KeyValuePair("ActionName", _action.DisplayName); + } + throw new IndexOutOfRangeException(nameof(index)); + } + } + + public int Count + { + get + { + return 2; + } + } + + public IEnumerator> GetEnumerator() + { + for (int i = 0; i < Count; ++i) + { + yield return this[i]; + } } public override string ToString() @@ -397,6 +421,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal // you have text logging, you can already use the requestId for correlation. return _action.DisplayName; } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs index 6b604aa2cd..753241a925 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using Microsoft.AspNetCore.Mvc.ViewComponents; @@ -192,7 +193,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal _viewNotFound(logger, viewName, searchedLocations, null); } - private class ViewComponentLogScope : ILogValues + private class ViewComponentLogScope : IReadOnlyList> { private readonly ViewComponentDescriptor _descriptor; @@ -201,19 +202,47 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal _descriptor = descriptor; } - public IEnumerable> GetValues() + public KeyValuePair this[int index] { - return new KeyValuePair[] + get { - new KeyValuePair("ViewComponentName", _descriptor.DisplayName), - new KeyValuePair("ViewComponentId", _descriptor.Id), - }; + if (index == 0) + { + return new KeyValuePair("ViewComponentName", _descriptor.DisplayName); + } + else if (index == 1) + { + return new KeyValuePair("ViewComponentId", _descriptor.Id); + } + throw new IndexOutOfRangeException(nameof(index)); + } + } + + public int Count + { + get + { + return 2; + } + } + + public IEnumerator> GetEnumerator() + { + for (int i = 0; i < Count; ++i) + { + yield return this[i]; + } } public override string ToString() { return _descriptor.DisplayName; } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } } diff --git a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/TagHelperLogger.cs b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/TagHelperLogger.cs index a5f091e285..0ccc76bf2d 100644 --- a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/TagHelperLogger.cs +++ b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/TagHelperLogger.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers return true; } - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { Logged.Add(new LoggerData(logLevel, state)); }