Skip to content

Commit

Permalink
(GH-1309) Support this.Log.Trace()
Browse files Browse the repository at this point in the history
Allow calling trace directly and have it do the appropriate thing. If
trace is called through a logger, redirect to the trace method.
  • Loading branch information
ferventcoder committed May 29, 2017
1 parent 5469ccd commit 95f2d0e
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/chocolatey/ILogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ namespace chocolatey
/// </summary>
public static class ILogExtensions
{
/// <summary>
/// This is changed for testing only
/// </summary>
public static bool LogTraceMessages = true;

public static void Trace(this ILog logger, string message, params object[] formatting)
{
if (LogTraceMessages) ChocolateyLoggers.Trace.to_string().Log().Debug(message, formatting);
}

public static void Trace(this ILog logger, Func<string> message)
{
if (LogTraceMessages) ChocolateyLoggers.Trace.to_string().Log().Debug(message);
}

public static void Debug(this ILog logger, ChocolateyLoggers logType, string message, params object[] formatting)
{
switch (logType)
Expand All @@ -34,6 +49,9 @@ public static void Debug(this ILog logger, ChocolateyLoggers logType, string mes

logger.Debug(message, formatting);
break;
case ChocolateyLoggers.Trace:
Trace(logger,message,formatting);
break;
default:
logType.to_string().Log().Debug(message, formatting);
break;
Expand All @@ -47,6 +65,9 @@ public static void Debug(this ILog logger, ChocolateyLoggers logType, Func<strin
case ChocolateyLoggers.Normal:
logger.Debug(message);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message);
break;
default:
logType.to_string().Log().Debug(message);
break;
Expand All @@ -58,9 +79,11 @@ public static void Info(this ILog logger, ChocolateyLoggers logType, string mess
switch (logType)
{
case ChocolateyLoggers.Normal:

logger.Info(message, formatting);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message, formatting);
break;
default:
logType.to_string().Log().Info(message, formatting);
break;
Expand All @@ -74,6 +97,9 @@ public static void Info(this ILog logger, ChocolateyLoggers logType, Func<string
case ChocolateyLoggers.Normal:
logger.Info(message);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message);
break;
default:
logType.to_string().Log().Info(message);
break;
Expand All @@ -85,9 +111,11 @@ public static void Warn(this ILog logger, ChocolateyLoggers logType, string mess
switch (logType)
{
case ChocolateyLoggers.Normal:

logger.Warn(message, formatting);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message, formatting);
break;
default:
logType.to_string().Log().Warn(message, formatting);
break;
Expand All @@ -101,6 +129,9 @@ public static void Warn(this ILog logger, ChocolateyLoggers logType, Func<string
case ChocolateyLoggers.Normal:
logger.Warn(message);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message);
break;
default:
logType.to_string().Log().Warn(message);
break;
Expand All @@ -112,9 +143,11 @@ public static void Error(this ILog logger, ChocolateyLoggers logType, string mes
switch (logType)
{
case ChocolateyLoggers.Normal:

logger.Error(message, formatting);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message, formatting);
break;
default:
logType.to_string().Log().Error(message, formatting);
break;
Expand All @@ -128,6 +161,9 @@ public static void Error(this ILog logger, ChocolateyLoggers logType, Func<strin
case ChocolateyLoggers.Normal:
logger.Error(message);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message);
break;
default:
logType.to_string().Log().Error(message);
break;
Expand All @@ -139,9 +175,11 @@ public static void Fatal(this ILog logger, ChocolateyLoggers logType, string mes
switch (logType)
{
case ChocolateyLoggers.Normal:

logger.Fatal(message, formatting);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message, formatting);
break;
default:
logType.to_string().Log().Fatal(message, formatting);
break;
Expand All @@ -155,6 +193,9 @@ public static void Fatal(this ILog logger, ChocolateyLoggers logType, Func<strin
case ChocolateyLoggers.Normal:
logger.Fatal(message);
break;
case ChocolateyLoggers.Trace:
Trace(logger, message);
break;
default:
logType.to_string().Log().Fatal(message);
break;
Expand Down

0 comments on commit 95f2d0e

Please sign in to comment.