This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release' of github.com:aspnet/Logging into release
- Loading branch information
Showing
13 changed files
with
137 additions
and
58 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Logging | ||
======= | ||
|
||
Contains common logging abstractions for ASP.NET vNext. Refer to the [wiki](https://github.com/aspnet/Logging/wiki) for more information | ||
Contains common logging abstractions for ASP.NET 5. Refer to the [wiki](https://github.com/aspnet/Logging/wiki) for more information | ||
|
||
This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo. | ||
This project is part of ASP.NET 5. You can find samples, documentation and getting started instructions for ASP.NET 5 at the [Home](https://github.com/aspnet/home) repo. |
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
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
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
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
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
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 |
---|---|---|
@@ -1,18 +1,11 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"dependencies": { | ||
"Microsoft.Framework.Logging": "1.0.0-*", | ||
"NLog": "3.1.0" | ||
}, | ||
"frameworks": { | ||
"net45": { | ||
"dependencies": { | ||
"Microsoft.Framework.Logging.Interfaces": "1.0.0-*" | ||
} | ||
}, | ||
"aspnet50": { | ||
"dependencies": { | ||
"Microsoft.Framework.Logging.Interfaces": { "version": "1.0.0-*", "type": "build" } | ||
} | ||
} | ||
"net45": { }, | ||
"aspnet50": { } | ||
} | ||
} |
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
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
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,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
|
||
namespace Microsoft.Framework.Logging | ||
{ | ||
/// <summary> | ||
/// Formatters for common logging scenarios. | ||
/// </summary> | ||
public static class LogFormatter | ||
{ | ||
private const string space = " "; | ||
|
||
/// <summary> | ||
/// Formats a message from the given state and exception, in the form | ||
/// "state | ||
/// exception". | ||
/// If state is an <see cref="ILoggerStructure"/>, <see cref="LogFormatter.FormatStructure(ILoggerStructure)"/> | ||
/// is used to format the message, otherwise the state's ToString() is used. | ||
/// </summary> | ||
public static string Formatter(object state, Exception e) | ||
{ | ||
var result = string.Empty; | ||
if (state != null) | ||
{ | ||
var structure = state as ILoggerStructure; | ||
if (structure != null) | ||
{ | ||
result += FormatStructure(structure); | ||
} | ||
else | ||
{ | ||
result += state; | ||
} | ||
} | ||
if (e != null) | ||
{ | ||
result += Environment.NewLine + e; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Formats an <see cref="ILoggerStructure"/>. | ||
/// </summary> | ||
/// <param name="structure">The <see cref="ILoggerStructure"/> to format.</param> | ||
/// <returns>A string representation of the given <see cref="ILoggerStructure"/>.</returns> | ||
public static string FormatStructure([NotNull] ILoggerStructure structure) | ||
{ | ||
var builder = new StringBuilder(); | ||
FormatStructure(structure, builder); | ||
return builder.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Formats an <see cref="ILoggerStructure"/>. | ||
/// </summary> | ||
/// <param name="structure">The <see cref="ILoggerStructure"/> to format.</param> | ||
/// <param name="builder">The <see cref="StringBuilder"/> to append to.</param> | ||
private static void FormatStructure([NotNull] ILoggerStructure structure, [NotNull] StringBuilder builder) | ||
{ | ||
var values = structure.GetValues(); | ||
if (values == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var kvp in values) | ||
{ | ||
IEnumerable<ILoggerStructure> structureEnumerable; | ||
ILoggerStructure loggerStructure; | ||
builder.Append(kvp.Key); | ||
builder.Append(": "); | ||
if ((structureEnumerable = kvp.Value as IEnumerable<ILoggerStructure>) != null) | ||
{ | ||
var valArray = structureEnumerable.ToArray(); | ||
for (int j = 0; j < valArray.Length - 1; j++) | ||
{ | ||
FormatStructure(valArray[j], builder); | ||
builder.Append(", "); | ||
} | ||
if (valArray.Length > 0) | ||
{ | ||
FormatStructure(valArray[valArray.Length - 1], builder); | ||
} | ||
} | ||
else if ((loggerStructure = kvp.Value as ILoggerStructure) != null) | ||
{ | ||
FormatStructure(loggerStructure, builder); | ||
} | ||
else | ||
{ | ||
builder.Append(kvp.Value); | ||
} | ||
builder.Append(space); | ||
} | ||
// get rid of the extra whitespace | ||
if (builder.Length > 0) | ||
{ | ||
builder.Length -= space.Length; | ||
} | ||
} | ||
} | ||
} |
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
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
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