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

Commit

Permalink
Merge pull request #790 from ChrisSimmons/ExpandLogLevelExtension
Browse files Browse the repository at this point in the history
Expand log level extension
  • Loading branch information
pakrym authored Apr 16, 2018
2 parents 602e10e + a113909 commit 3821274
Show file tree
Hide file tree
Showing 2 changed files with 329 additions and 154 deletions.
211 changes: 65 additions & 146 deletions src/Microsoft.Extensions.Logging.Abstractions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public static class LoggerExtensions
/// <example>logger.LogDebug(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogDebug(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Debug, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Debug, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -46,12 +41,7 @@ public static void LogDebug(this ILogger logger, EventId eventId, Exception exce
/// <example>logger.LogDebug(0, "Processing request from {Address}", address)</example>
public static void LogDebug(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Debug, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Debug, eventId, message, args);
}

/// <summary>
Expand All @@ -64,12 +54,7 @@ public static void LogDebug(this ILogger logger, EventId eventId, string message
/// <example>logger.LogDebug(exception, "Error while processing request from {Address}", address)</example>
public static void LogDebug(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Debug, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Debug, exception, message, args);
}

/// <summary>
Expand All @@ -81,12 +66,7 @@ public static void LogDebug(this ILogger logger, Exception exception, string mes
/// <example>logger.LogDebug("Processing request from {Address}", address)</example>
public static void LogDebug(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Debug, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Debug, message, args);
}

//------------------------------------------TRACE------------------------------------------//
Expand All @@ -102,12 +82,7 @@ public static void LogDebug(this ILogger logger, string message, params object[]
/// <example>logger.LogTrace(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogTrace(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Trace, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Trace, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -120,12 +95,7 @@ public static void LogTrace(this ILogger logger, EventId eventId, Exception exce
/// <example>logger.LogTrace(0, "Processing request from {Address}", address)</example>
public static void LogTrace(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Trace, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Trace, eventId, message, args);
}

/// <summary>
Expand All @@ -138,12 +108,7 @@ public static void LogTrace(this ILogger logger, EventId eventId, string message
/// <example>logger.LogTrace(exception, "Error while processing request from {Address}", address)</example>
public static void LogTrace(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Trace, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Trace, exception, message, args);
}

/// <summary>
Expand All @@ -155,12 +120,7 @@ public static void LogTrace(this ILogger logger, Exception exception, string mes
/// <example>logger.LogTrace("Processing request from {Address}", address)</example>
public static void LogTrace(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Trace, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Trace, message, args);
}

//------------------------------------------INFORMATION------------------------------------------//
Expand All @@ -176,12 +136,7 @@ public static void LogTrace(this ILogger logger, string message, params object[]
/// <example>logger.LogInformation(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogInformation(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Information, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Information, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -194,12 +149,7 @@ public static void LogInformation(this ILogger logger, EventId eventId, Exceptio
/// <example>logger.LogInformation(0, "Processing request from {Address}", address)</example>
public static void LogInformation(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Information, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Information, eventId, message, args);
}

/// <summary>
Expand All @@ -212,12 +162,7 @@ public static void LogInformation(this ILogger logger, EventId eventId, string m
/// <example>logger.LogInformation(exception, "Error while processing request from {Address}", address)</example>
public static void LogInformation(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Information, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Information, exception, message, args);
}

/// <summary>
Expand All @@ -229,12 +174,7 @@ public static void LogInformation(this ILogger logger, Exception exception, stri
/// <example>logger.LogInformation("Processing request from {Address}", address)</example>
public static void LogInformation(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Information, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Information, message, args);
}

//------------------------------------------WARNING------------------------------------------//
Expand All @@ -250,12 +190,7 @@ public static void LogInformation(this ILogger logger, string message, params ob
/// <example>logger.LogWarning(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogWarning(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Warning, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Warning, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -268,12 +203,7 @@ public static void LogWarning(this ILogger logger, EventId eventId, Exception ex
/// <example>logger.LogWarning(0, "Processing request from {Address}", address)</example>
public static void LogWarning(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Warning, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Warning, eventId, message, args);
}

/// <summary>
Expand All @@ -286,12 +216,7 @@ public static void LogWarning(this ILogger logger, EventId eventId, string messa
/// <example>logger.LogWarning(exception, "Error while processing request from {Address}", address)</example>
public static void LogWarning(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Warning, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Warning, exception, message, args);
}

/// <summary>
Expand All @@ -303,12 +228,7 @@ public static void LogWarning(this ILogger logger, Exception exception, string m
/// <example>logger.LogWarning("Processing request from {Address}", address)</example>
public static void LogWarning(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Warning, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Warning, message, args);
}

//------------------------------------------ERROR------------------------------------------//
Expand All @@ -324,12 +244,7 @@ public static void LogWarning(this ILogger logger, string message, params object
/// <example>logger.LogError(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogError(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Error, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Error, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -342,12 +257,7 @@ public static void LogError(this ILogger logger, EventId eventId, Exception exce
/// <example>logger.LogError(0, "Processing request from {Address}", address)</example>
public static void LogError(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Error, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Error, eventId, message, args);
}

/// <summary>
Expand All @@ -360,12 +270,7 @@ public static void LogError(this ILogger logger, EventId eventId, string message
/// <example>logger.LogError(exception, "Error while processing request from {Address}", address)</example>
public static void LogError(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Error, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Error, exception, message, args);
}

/// <summary>
Expand All @@ -377,12 +282,7 @@ public static void LogError(this ILogger logger, Exception exception, string mes
/// <example>logger.LogError("Processing request from {Address}", address)</example>
public static void LogError(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Error, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Error, message, args);
}

//------------------------------------------CRITICAL------------------------------------------//
Expand All @@ -398,12 +298,7 @@ public static void LogError(this ILogger logger, string message, params object[]
/// <example>logger.LogCritical(0, exception, "Error while processing request from {Address}", address)</example>
public static void LogCritical(this ILogger logger, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Critical, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Critical, eventId, exception, message, args);
}

/// <summary>
Expand All @@ -416,12 +311,7 @@ public static void LogCritical(this ILogger logger, EventId eventId, Exception e
/// <example>logger.LogCritical(0, "Processing request from {Address}", address)</example>
public static void LogCritical(this ILogger logger, EventId eventId, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Critical, eventId, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(LogLevel.Critical, eventId, message, args);
}

/// <summary>
Expand All @@ -434,12 +324,7 @@ public static void LogCritical(this ILogger logger, EventId eventId, string mess
/// <example>logger.LogCritical(exception, "Error while processing request from {Address}", address)</example>
public static void LogCritical(this ILogger logger, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(LogLevel.Critical, 0, new FormattedLogValues(message, args), exception, _messageFormatter);
logger.Log(LogLevel.Critical, exception, message, args);
}

/// <summary>
Expand All @@ -451,30 +336,64 @@ public static void LogCritical(this ILogger logger, Exception exception, string
/// <example>logger.LogCritical("Processing request from {Address}", address)</example>
public static void LogCritical(this ILogger logger, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
logger.Log(LogLevel.Critical, message, args);
}

logger.Log(LogLevel.Critical, 0, new FormattedLogValues(message, args), null, _messageFormatter);
/// <summary>
/// Formats and writes a log message at the specified log level.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="logLevel">Entry will be written on this level.</param>
/// <param name="message">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 Log(this ILogger logger, LogLevel logLevel, string message, params object[] args)
{
logger.Log(logLevel, 0, null, message, args);
}

/// <summary>
/// Formats and writes a log message at the specified log level.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="logLevel">Entry will be written on this level.</param>
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="message">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 Log(this ILogger logger, LogLevel logLevel, EventId eventId, string message, params object[] args)
{
logger.Log(logLevel, eventId, null, message, args);
}

/// <summary>
/// Formats and writes a log message on specified log level.
/// Formats and writes a log message at the specified log level.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="logLevel">Entry will be written on this level.</param>
/// <param name="exception">The exception to log.</param>
/// <param name="message">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 Log(this ILogger logger, LogLevel logLevel, string message, params object[] args)
public static void Log(this ILogger logger, LogLevel logLevel, Exception exception, string message, params object[] args)
{
logger.Log(logLevel, 0, exception, message, args);
}

/// <summary>
/// Formats and writes a log message at the specified log level.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> to write to.</param>
/// <param name="logLevel">Entry will be written on this level.</param>
/// <param name="eventId">The event id associated with the log.</param>
/// <param name="exception">The exception to log.</param>
/// <param name="message">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 Log(this ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, string message, params object[] args)
{
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

logger.Log(logLevel, 0, new FormattedLogValues(message, args), null, _messageFormatter);
logger.Log(logLevel, eventId, new FormattedLogValues(message, args), exception, _messageFormatter);
}

//------------------------------------------Scope------------------------------------------//
Expand Down
Loading

0 comments on commit 3821274

Please sign in to comment.