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

Commit

Permalink
Merge branch 'release' of github.com:aspnet/Logging into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengTian committed Jan 29, 2015
2 parents 8dfc107 + 11bde39 commit af88baa
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 58 deletions.
4 changes: 2 additions & 2 deletions README.md
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.
8 changes: 4 additions & 4 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion

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

:run
CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
fi

if ! type k > /dev/null 2>&1; then
source packages/KoreBuild/build/kvm.sh
source packages/KoreBuild/build/dotnetsdk.sh
fi

if ! type k > /dev/null 2>&1; then
kvm upgrade
dotnetsdk upgrade
fi

mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
9 changes: 1 addition & 8 deletions src/Microsoft.Framework.Logging.Console/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ public void Write(LogLevel logLevel, int eventId, object state, Exception except
}
else
{
if (state != null)
{
message += state;
}
if (exception != null)
{
message += Environment.NewLine + exception;
}
message = LogFormatter.Formatter(state, exception);
}
if (string.IsNullOrEmpty(message))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Framework.Logging.Interfaces/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.Framework.Logging
public interface ILogger
{
/// <summary>
/// Aggregates most logging patterns to a single method. This must be compatible with the Func representation in the OWIN environment.
/// Aggregates most logging patterns to a single method.
/// </summary>
/// <param name="logLevel"></param>
/// <param name="eventId"></param>
Expand Down
9 changes: 1 addition & 8 deletions src/Microsoft.Framework.Logging.NLog/NLogLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ public void Write(
}
else
{
if (state != null)
{
message += state;
}
if (exception != null)
{
message += Environment.NewLine + exception;
}
LogFormatter.Formatter(state, exception);
}
if (!string.IsNullOrEmpty(message))
{
Expand Down
13 changes: 3 additions & 10 deletions src/Microsoft.Framework.Logging.NLog/project.json
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": { }
}
}
9 changes: 1 addition & 8 deletions src/Microsoft.Framework.Logging.Serilog/SerilogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ public void Write(LogLevel logLevel, int eventId, object state, Exception except
}
else
{
if (state != null)
{
message += state;
}
if (exception != null)
{
message += Environment.NewLine + exception;
}
message = LogFormatter.Formatter(state, exception);
}
if (string.IsNullOrEmpty(message))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DiagnosticsLoggerProvider : ILoggerProvider
/// Initializes a new instance of the <see cref="DiagnosticsLoggerProvider"/> class.
/// </summary>
/// <summary>
/// Creates a factory named "Microsoft.Owin".
/// Creates a factory named "Microsoft.AspNet".
/// </summary>
public DiagnosticsLoggerProvider()
{
Expand Down
107 changes: 107 additions & 0 deletions src/Microsoft.Framework.Logging/LogFormatter.cs
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;
}
}
}
}
20 changes: 10 additions & 10 deletions src/Microsoft.Framework.Logging/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void WriteVerbose([NotNull] this ILogger logger, int eventId, stri
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteVerbose([NotNull] this ILogger logger, string format, params string[] args)
public static void WriteVerbose([NotNull] this ILogger logger, string format, params object[] args)
{
logger.Write(LogLevel.Verbose, 0,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand All @@ -61,7 +61,7 @@ public static void WriteVerbose([NotNull] this ILogger logger, string format, pa
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteVerbose([NotNull] this ILogger logger, int eventId, string format, params string[] args)
public static void WriteVerbose([NotNull] this ILogger logger, int eventId, string format, params object[] args)
{
logger.Write(LogLevel.Verbose, eventId,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand Down Expand Up @@ -126,7 +126,7 @@ public static void WriteInformation([NotNull] this ILogger logger, int eventId,
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteInformation([NotNull] this ILogger logger, string format, params string[] args)
public static void WriteInformation([NotNull] this ILogger logger, string format, params object[] args)
{
logger.Write(LogLevel.Information, 0,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand All @@ -139,7 +139,7 @@ public static void WriteInformation([NotNull] this ILogger logger, string format
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteInformation([NotNull] this ILogger logger, int eventId, string format, params string[] args)
public static void WriteInformation([NotNull] this ILogger logger, int eventId, string format, params object[] args)
{
logger.Write(LogLevel.Information, eventId,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand Down Expand Up @@ -204,7 +204,7 @@ public static void WriteWarning([NotNull] this ILogger logger, int eventId, stri
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteWarning([NotNull] this ILogger logger, string format, params string[] args)
public static void WriteWarning([NotNull] this ILogger logger, string format, params object[] args)
{
logger.Write(LogLevel.Warning, 0,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand All @@ -217,7 +217,7 @@ public static void WriteWarning([NotNull] this ILogger logger, string format, pa
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteWarning([NotNull] this ILogger logger, int eventId, string format, params string[] args)
public static void WriteWarning([NotNull] this ILogger logger, int eventId, string format, params object[] args)
{
logger.Write(LogLevel.Warning, eventId,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand Down Expand Up @@ -305,7 +305,7 @@ public static void WriteError([NotNull] this ILogger logger, int eventId, string
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteError([NotNull] this ILogger logger, string format, params string[] args)
public static void WriteError([NotNull] this ILogger logger, string format, params object[] args)
{
logger.Write(LogLevel.Error, 0,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand All @@ -318,7 +318,7 @@ public static void WriteError([NotNull] this ILogger logger, string format, para
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteError([NotNull] this ILogger logger, int eventId, string format, params string[] args)
public static void WriteError([NotNull] this ILogger logger, int eventId, string format, params object[] args)
{
logger.Write(LogLevel.Error, eventId,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand Down Expand Up @@ -406,7 +406,7 @@ public static void WriteCritical([NotNull] this ILogger logger, int eventId, str
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteCritical([NotNull] this ILogger logger, string format, params string[] args)
public static void WriteCritical([NotNull] this ILogger logger, string format, params object[] args)
{
logger.Write(LogLevel.Critical, 0,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand All @@ -419,7 +419,7 @@ public static void WriteCritical([NotNull] this ILogger logger, string format, p
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="format">Format string of the log message.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public static void WriteCritical([NotNull] this ILogger logger, int eventId, string format, params string[] args)
public static void WriteCritical([NotNull] this ILogger logger, int eventId, string format, params object[] args)
{
logger.Write(LogLevel.Critical, eventId,
string.Format(CultureInfo.InvariantCulture, format, args), null, TheMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Framework.Logging/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"System.Diagnostics.TraceSource": "4.0.0-beta-*",
"System.Globalization": "4.0.10-beta-*",
"System.Linq": "4.0.0-beta-*",
"System.Threading": "4.0.0-beta-*",
"System.Threading": "4.0.10-beta-*",
"Microsoft.Framework.Logging.Interfaces": { "version": "1.0.0-*", "type": "build" }
}
},
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.Framework.Logging.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"dependencies": {
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Microsoft.Framework.Logging.Serilog": "1.0.0-*",
"Xunit.KRunner": "1.0.0-*"
"xunit.runner.kre": "1.0.0-*"
},
"commands": {
"run": "Xunit.KRunner",
"test": "Xunit.KRunner"
"run": "xunit.runner.kre",
"test": "xunit.runner.kre"
},
"frameworks": {
"aspnet50": {
Expand Down

0 comments on commit af88baa

Please sign in to comment.