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

Commit af88baa

Browse files
committed
Merge branch 'release' of github.com:aspnet/Logging into release
2 parents 8dfc107 + 11bde39 commit af88baa

File tree

13 files changed

+137
-58
lines changed

13 files changed

+137
-58
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Logging
22
=======
33

4-
Contains common logging abstractions for ASP.NET vNext. Refer to the [wiki](https://github.com/aspnet/Logging/wiki) for more information
4+
Contains common logging abstractions for ASP.NET 5. Refer to the [wiki](https://github.com/aspnet/Logging/wiki) for more information
55

6-
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.
6+
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.

build.cmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ IF EXIST packages\KoreBuild goto run
1919
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
2020
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
2121

22-
IF "%SKIP_KRE_INSTALL%"=="1" goto run
23-
CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86
24-
CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86
22+
IF "%SKIP_DOTNET_INSTALL%"=="1" goto run
23+
CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86
24+
CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86
2525

2626
:run
27-
CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
27+
CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86
2828
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
2828
fi
2929

3030
if ! type k > /dev/null 2>&1; then
31-
source packages/KoreBuild/build/kvm.sh
31+
source packages/KoreBuild/build/dotnetsdk.sh
3232
fi
3333

3434
if ! type k > /dev/null 2>&1; then
35-
kvm upgrade
35+
dotnetsdk upgrade
3636
fi
3737

3838
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"

src/Microsoft.Framework.Logging.Console/ConsoleLogger.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ public void Write(LogLevel logLevel, int eventId, object state, Exception except
5252
}
5353
else
5454
{
55-
if (state != null)
56-
{
57-
message += state;
58-
}
59-
if (exception != null)
60-
{
61-
message += Environment.NewLine + exception;
62-
}
55+
message = LogFormatter.Formatter(state, exception);
6356
}
6457
if (string.IsNullOrEmpty(message))
6558
{

src/Microsoft.Framework.Logging.Interfaces/ILogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.Framework.Logging
1414
public interface ILogger
1515
{
1616
/// <summary>
17-
/// Aggregates most logging patterns to a single method. This must be compatible with the Func representation in the OWIN environment.
17+
/// Aggregates most logging patterns to a single method.
1818
/// </summary>
1919
/// <param name="logLevel"></param>
2020
/// <param name="eventId"></param>

src/Microsoft.Framework.Logging.NLog/NLogLoggerProvider.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,7 @@ public void Write(
4444
}
4545
else
4646
{
47-
if (state != null)
48-
{
49-
message += state;
50-
}
51-
if (exception != null)
52-
{
53-
message += Environment.NewLine + exception;
54-
}
47+
LogFormatter.Formatter(state, exception);
5548
}
5649
if (!string.IsNullOrEmpty(message))
5750
{
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
{
22
"version": "1.0.0-*",
33
"dependencies": {
4+
"Microsoft.Framework.Logging": "1.0.0-*",
45
"NLog": "3.1.0"
56
},
67
"frameworks": {
7-
"net45": {
8-
"dependencies": {
9-
"Microsoft.Framework.Logging.Interfaces": "1.0.0-*"
10-
}
11-
},
12-
"aspnet50": {
13-
"dependencies": {
14-
"Microsoft.Framework.Logging.Interfaces": { "version": "1.0.0-*", "type": "build" }
15-
}
16-
}
8+
"net45": { },
9+
"aspnet50": { }
1710
}
1811
}

src/Microsoft.Framework.Logging.Serilog/SerilogLogger.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ public void Write(LogLevel logLevel, int eventId, object state, Exception except
5353
}
5454
else
5555
{
56-
if (state != null)
57-
{
58-
message += state;
59-
}
60-
if (exception != null)
61-
{
62-
message += Environment.NewLine + exception;
63-
}
56+
message = LogFormatter.Formatter(state, exception);
6457
}
6558
if (string.IsNullOrEmpty(message))
6659
{

src/Microsoft.Framework.Logging/DiagnosticsLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DiagnosticsLoggerProvider : ILoggerProvider
2323
/// Initializes a new instance of the <see cref="DiagnosticsLoggerProvider"/> class.
2424
/// </summary>
2525
/// <summary>
26-
/// Creates a factory named "Microsoft.Owin".
26+
/// Creates a factory named "Microsoft.AspNet".
2727
/// </summary>
2828
public DiagnosticsLoggerProvider()
2929
{
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using JetBrains.Annotations;
6+
7+
namespace Microsoft.Framework.Logging
8+
{
9+
/// <summary>
10+
/// Formatters for common logging scenarios.
11+
/// </summary>
12+
public static class LogFormatter
13+
{
14+
private const string space = " ";
15+
16+
/// <summary>
17+
/// Formats a message from the given state and exception, in the form
18+
/// "state
19+
/// exception".
20+
/// If state is an <see cref="ILoggerStructure"/>, <see cref="LogFormatter.FormatStructure(ILoggerStructure)"/>
21+
/// is used to format the message, otherwise the state's ToString() is used.
22+
/// </summary>
23+
public static string Formatter(object state, Exception e)
24+
{
25+
var result = string.Empty;
26+
if (state != null)
27+
{
28+
var structure = state as ILoggerStructure;
29+
if (structure != null)
30+
{
31+
result += FormatStructure(structure);
32+
}
33+
else
34+
{
35+
result += state;
36+
}
37+
}
38+
if (e != null)
39+
{
40+
result += Environment.NewLine + e;
41+
}
42+
43+
return result;
44+
}
45+
46+
/// <summary>
47+
/// Formats an <see cref="ILoggerStructure"/>.
48+
/// </summary>
49+
/// <param name="structure">The <see cref="ILoggerStructure"/> to format.</param>
50+
/// <returns>A string representation of the given <see cref="ILoggerStructure"/>.</returns>
51+
public static string FormatStructure([NotNull] ILoggerStructure structure)
52+
{
53+
var builder = new StringBuilder();
54+
FormatStructure(structure, builder);
55+
return builder.ToString();
56+
}
57+
58+
/// <summary>
59+
/// Formats an <see cref="ILoggerStructure"/>.
60+
/// </summary>
61+
/// <param name="structure">The <see cref="ILoggerStructure"/> to format.</param>
62+
/// <param name="builder">The <see cref="StringBuilder"/> to append to.</param>
63+
private static void FormatStructure([NotNull] ILoggerStructure structure, [NotNull] StringBuilder builder)
64+
{
65+
var values = structure.GetValues();
66+
if (values == null)
67+
{
68+
return;
69+
}
70+
71+
foreach (var kvp in values)
72+
{
73+
IEnumerable<ILoggerStructure> structureEnumerable;
74+
ILoggerStructure loggerStructure;
75+
builder.Append(kvp.Key);
76+
builder.Append(": ");
77+
if ((structureEnumerable = kvp.Value as IEnumerable<ILoggerStructure>) != null)
78+
{
79+
var valArray = structureEnumerable.ToArray();
80+
for (int j = 0; j < valArray.Length - 1; j++)
81+
{
82+
FormatStructure(valArray[j], builder);
83+
builder.Append(", ");
84+
}
85+
if (valArray.Length > 0)
86+
{
87+
FormatStructure(valArray[valArray.Length - 1], builder);
88+
}
89+
}
90+
else if ((loggerStructure = kvp.Value as ILoggerStructure) != null)
91+
{
92+
FormatStructure(loggerStructure, builder);
93+
}
94+
else
95+
{
96+
builder.Append(kvp.Value);
97+
}
98+
builder.Append(space);
99+
}
100+
// get rid of the extra whitespace
101+
if (builder.Length > 0)
102+
{
103+
builder.Length -= space.Length;
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)