Add event name in routing (#6455)

This commit is contained in:
James Newton-King 2019-01-09 12:01:14 +13:00 committed by GitHub
parent 6a98c68628
commit aadbed62de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 19 deletions

View File

@ -8,24 +8,24 @@ namespace Microsoft.AspNetCore.Routing.Logging
{
internal static class RouteConstraintMatcherExtensions
{
private static readonly Action<ILogger, object, string, IRouteConstraint, Exception> _routeValueDoesNotMatchConstraint;
private static readonly Action<ILogger, object, string, IRouteConstraint, Exception> _constraintNotMatched;
static RouteConstraintMatcherExtensions()
{
_routeValueDoesNotMatchConstraint = LoggerMessage.Define<object, string, IRouteConstraint>(
_constraintNotMatched = LoggerMessage.Define<object, string, IRouteConstraint>(
LogLevel.Debug,
1,
new EventId(1, "ConstraintNotMatched"),
"Route value '{RouteValue}' with key '{RouteKey}' did not match " +
"the constraint '{RouteConstraint}'");
}
public static void RouteValueDoesNotMatchConstraint(
public static void ConstraintNotMatched(
this ILogger logger,
object routeValue,
string routeKey,
IRouteConstraint routeConstraint)
{
_routeValueDoesNotMatchConstraint(logger, routeValue, routeKey, routeConstraint, null);
_constraintNotMatched(logger, routeValue, routeKey, routeConstraint, null);
}
}
}

View File

@ -8,19 +8,19 @@ namespace Microsoft.AspNetCore.Routing.Logging
{
internal static class RouterMiddlewareLoggerExtensions
{
private static readonly Action<ILogger, Exception> _requestDidNotMatchRoutes;
private static readonly Action<ILogger, Exception> _requestNotMatched;
static RouterMiddlewareLoggerExtensions()
{
_requestDidNotMatchRoutes = LoggerMessage.Define(
_requestNotMatched = LoggerMessage.Define(
LogLevel.Debug,
1,
new EventId(1, "RequestNotMatched"),
"Request did not match any routes");
}
public static void RequestDidNotMatchRoutes(this ILogger logger)
public static void RequestNotMatched(this ILogger logger)
{
_requestDidNotMatchRoutes(logger, null);
_requestNotMatched(logger, null);
}
}
}

View File

@ -8,22 +8,22 @@ namespace Microsoft.AspNetCore.Routing.Logging
{
internal static class TreeRouterLoggerExtensions
{
private static readonly Action<ILogger, string, string, Exception> _matchedRoute;
private static readonly Action<ILogger, string, string, Exception> _requestMatchedRoute;
static TreeRouterLoggerExtensions()
{
_matchedRoute = LoggerMessage.Define<string, string>(
_requestMatchedRoute = LoggerMessage.Define<string, string>(
LogLevel.Debug,
1,
new EventId(1, "RequestMatchedRoute"),
"Request successfully matched the route with name '{RouteName}' and template '{RouteTemplate}'");
}
public static void MatchedRoute(
public static void RequestMatchedRoute(
this ILogger logger,
string routeName,
string routeTemplate)
{
_matchedRoute(logger, routeName, routeTemplate, null);
_requestMatchedRoute(logger, routeName, routeTemplate, null);
}
}
}

View File

@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Routing
{
return Task.CompletedTask;
}
_logger.MatchedRoute(Name, ParsedTemplate.TemplateText);
_logger.RequestMatchedRoute(Name, ParsedTemplate.TemplateText);
return OnRouteMatched(context);
}

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Routing
{
routeValues.TryGetValue(kvp.Key, out var routeValue);
logger.RouteValueDoesNotMatchConstraint(routeValue, kvp.Key, kvp.Value);
logger.ConstraintNotMatched(routeValue, kvp.Key, kvp.Value);
}
return false;

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Builder
if (context.Handler == null)
{
_logger.RequestDidNotMatchRoutes();
_logger.RequestNotMatched();
await _next.Invoke(httpContext);
}
else

View File

@ -208,7 +208,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
continue;
}
_logger.MatchedRoute(entry.RouteName, entry.RouteTemplate.TemplateText);
_logger.RequestMatchedRoute(entry.RouteName, entry.RouteTemplate.TemplateText);
context.RouteData.Routers.Add(entry.Handler);
await entry.Handler.RouteAsync(context);