This repository was archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scoped logging to RouterMiddleware, RouteCollection, and TemplateRoute.
- Loading branch information
Ben Brown
committed
Aug 1, 2014
1 parent
61436fb
commit fca9831
Showing
28 changed files
with
1,543 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
public static class LogFormatter | ||
{ | ||
/// <summary> | ||
/// A formatter for use with <see cref="Microsoft.Framework.Logging.ILogger.WriteCore( | ||
/// Framework.Logging.TraceType, | ||
/// int, | ||
/// object, | ||
/// Exception, Func{object, Exception, string})"/>. | ||
/// </summary> | ||
public static string Formatter(object o, Exception e) | ||
{ | ||
if (o != null && e != null) | ||
{ | ||
return o + Environment.NewLine + e; | ||
} | ||
|
||
if (o != null) | ||
{ | ||
return o.ToString(); | ||
} | ||
|
||
if (e != null) | ||
{ | ||
return e.ToString(); | ||
} | ||
|
||
return ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 Microsoft.Framework.Logging; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
internal static class LoggerExtensions | ||
{ | ||
public static bool WriteValues([NotNull] this ILogger logger, object values) | ||
{ | ||
return logger.WriteCore( | ||
eventType: TraceType.Information, | ||
eventId: 0, | ||
state: values, | ||
exception: null, | ||
formatter: LogFormatter.Formatter); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/Microsoft.AspNet.Routing/Logging/RouteCollectionRouteAsyncValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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 System.Text; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
/// <summary> | ||
/// Describes the state of | ||
/// <see cref="Microsoft.AspNet.Routing.RouteCollection.RouteAsync(RouteContext)"/>. | ||
/// </summary> | ||
public class RouteCollectionRouteAsyncValues | ||
{ | ||
/// <summary> | ||
/// The name of the state. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return "RouteCollection.RouteAsync"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The available routes. | ||
/// </summary> | ||
public IList<IRouter> Routes { get; set; } | ||
|
||
/// <summary> | ||
/// True if the request is handled. | ||
/// </summary> | ||
public bool Handled { get; set; } | ||
|
||
/// <summary> | ||
/// A summary of the data for display. | ||
/// </summary> | ||
public string Summary | ||
{ | ||
get | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine(Name); | ||
builder.Append("\tRoutes: "); | ||
StringBuilderHelpers.Append(builder, Routes); | ||
builder.AppendLine(); | ||
builder.Append("\tHandled? "); | ||
builder.Append(Handled); | ||
return builder.ToString(); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return Summary; | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/Microsoft.AspNet.Routing/Logging/RouteConstraintMatcherMatchValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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.Text; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
/// <summary> | ||
/// Describes the state of <see cref="RouteConstraintMatcher.Match( | ||
/// System.Collections.Generic.IDictionary{string, IRouteConstraint}, | ||
/// System.Collections.Generic.IDictionary{string, object}, | ||
/// Http.HttpContext, | ||
/// IRouter, | ||
/// RouteDirection, | ||
/// Framework.Logging.ILogger)"/>. | ||
/// </summary> | ||
public class RouteConstraintMatcherMatchValues | ||
{ | ||
/// <summary> | ||
/// The name of the state. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return "RouteConstraintMatcher.Match"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The key of the constraint. | ||
/// </summary> | ||
public string ConstraintKey { get; set; } | ||
|
||
/// <summary> | ||
/// The constraint. | ||
/// </summary> | ||
public IRouteConstraint Constraint { get; set; } | ||
|
||
/// <summary> | ||
/// True if the <see cref="Constraint"/> matched. | ||
/// </summary> | ||
public bool Matched { get; set; } | ||
|
||
/// <summary> | ||
/// A summary of the data for display. | ||
/// </summary> | ||
public string Summary | ||
{ | ||
get | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine(Name); | ||
builder.Append("\tConstraint key: "); | ||
builder.AppendLine(ConstraintKey); | ||
builder.Append("\tConstraint: "); | ||
builder.Append(Constraint); | ||
builder.AppendLine(); | ||
builder.Append("\tMatched? "); | ||
builder.Append(Matched); | ||
return builder.ToString(); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return Summary; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Microsoft.AspNet.Routing/Logging/RouterMiddlewareInvokeValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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.Text; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
/// <summary> | ||
/// Describes the state of | ||
/// <see cref="Microsoft.AspNet.Builder.RouterMiddleware.Invoke(Http.HttpContext)"/>. | ||
/// </summary> | ||
public class RouterMiddlewareInvokeValues | ||
{ | ||
/// <summary> | ||
/// The name of the state. | ||
/// </summary> | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return "RouterMiddleware.Invoke"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// True if the request is handled. | ||
/// </summary> | ||
public bool Handled { get; set; } | ||
|
||
/// <summary> | ||
/// A summary of the data for display. | ||
/// </summary> | ||
public string Summary | ||
{ | ||
get | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine(Name); | ||
builder.Append("\tHandled? "); | ||
builder.Append(Handled); | ||
return builder.ToString(); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return Summary; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Microsoft.AspNet.Routing/Logging/StringBuilderHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.AspNet.Routing.Logging | ||
{ | ||
internal static class StringBuilderHelpers | ||
{ | ||
public static void Append<T>(StringBuilder builder, IEnumerable<T> items) | ||
{ | ||
if (items == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var item in items) | ||
{ | ||
builder.Append(Environment.NewLine); | ||
builder.Append("\t\t"); | ||
builder.Append(item != null ? item.ToString() : "null"); | ||
} | ||
} | ||
|
||
public static void Append<K, V>(StringBuilder builder, IDictionary<K, V> dict) | ||
{ | ||
if (dict == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var kvp in dict) | ||
{ | ||
builder.Append(Environment.NewLine); | ||
builder.Append("\t\t"); | ||
builder.Append(kvp.Key != null ? kvp.Key.ToString() : "null"); | ||
builder.Append(" : "); | ||
builder.Append(kvp.Value != null ? kvp.Value.ToString() : "null"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.