Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit b034638

Browse files
committed
Added logger structure for route values
1 parent eebbc81 commit b034638

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.Framework.Logging;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace Microsoft.AspNet.Routing.Logging
9+
{
10+
public class RouteValuesLogValues : ILogValues
11+
{
12+
private readonly IDictionary<string, object> _routeValues;
13+
14+
public RouteValuesLogValues(IDictionary<string, object> routeValues)
15+
{
16+
_routeValues = routeValues;
17+
}
18+
19+
public IEnumerable<KeyValuePair<string, object>> GetValues()
20+
{
21+
return _routeValues;
22+
}
23+
24+
public override string ToString()
25+
{
26+
return string.Format(
27+
"Route values: {0}",
28+
string.Join(", ", _routeValues.Select(kvp => $"Key={kvp.Key};Value={kvp.Value}")));
29+
}
30+
}
31+
}

src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constrain
2222
return true;
2323
}
2424

25+
logger.LogVerbose("Verifying route constraints");
26+
if(constraints != null && constraints.Count == 0)
27+
{
28+
logger.LogVerbose("No route constraints found.");
29+
}
30+
2531
foreach (var kvp in constraints)
2632
{
2733
var constraint = kvp.Value;
34+
35+
logger.LogVerbose("Verifying constraint '{RouteConstraint}' for '{RouteKey}'", constraint, kvp.Key);
36+
2837
if (!constraint.Match(httpContext, route, kvp.Key, routeValues, routeDirection))
2938
{
3039
if (routeDirection.Equals(RouteDirection.IncomingRequest))

src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async virtual Task RouteAsync([NotNull] RouteContext context)
122122

123123
_logger.LogVerbose(
124124
"Request successfully matched the template of the route with name '{RouteName}' and template" +
125-
" '{RouteTemplate}'. Verifying constraints now...",
125+
" '{RouteTemplate}'.",
126126
Name,
127127
RouteTemplate);
128128

@@ -133,6 +133,8 @@ public async virtual Task RouteAsync([NotNull] RouteContext context)
133133
newRouteData.Routers.Add(_target);
134134
MergeValues(newRouteData.Values, values);
135135

136+
_logger.LogVerbose(new RouteValuesLogValues(newRouteData.Values));
137+
136138
if (!RouteConstraintMatcher.Match(
137139
Constraints,
138140
newRouteData.Values,

0 commit comments

Comments
 (0)