Skip to content

Commit

Permalink
Merge pull request #12 from aalex675/master
Browse files Browse the repository at this point in the history
Trace level log messages.
  • Loading branch information
ferventcoder committed Jul 27, 2017
2 parents 9a897f3 + bfcb938 commit 420534c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
15 changes: 14 additions & 1 deletion LoggingExtensions.Core/Logging/ILog.cs
Expand Up @@ -12,7 +12,20 @@ public interface ILog
/// </summary>
/// <param name="loggerName">Name of the logger</param>
void InitializeFor(string loggerName);


/// <summary>
/// Trace level of the specified message. The other method is preferred since the execution is deferred.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="formatting">The formatting.</param>
void Trace(string message, params object[] formatting);

/// <summary>
/// Trace level of the specified message.
/// </summary>
/// <param name="message">The message.</param>
void Trace(Func<string> message);

/// <summary>
/// Debug level of the specified message. The other method is preferred since the execution is deferred.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions LoggingExtensions.Core/Logging/NullLog.cs
Expand Up @@ -11,6 +11,14 @@ public void InitializeFor(string loggerName)
{
}

public void Trace(string message, params object[] formatting)
{
}

public void Trace(Func<string> message)
{
}

public void Debug(string message, params object[] formatting)
{
}
Expand Down
13 changes: 13 additions & 0 deletions LoggingExtensions.Moq/MockLogger.cs
Expand Up @@ -8,6 +8,7 @@

public enum LogLevel
{
Trace,
Debug,
Info,
Warn,
Expand Down Expand Up @@ -37,6 +38,18 @@ public void LogMessage(LogLevel logLevel, string message)
list.Add(message);
}

public void Trace(string message, params object[] formatting)
{
LogMessage(LogLevel.Trace, string.Format(message, formatting));
Object.Trace(message, formatting);
}

public void Trace(Func<string> message)
{
LogMessage(LogLevel.Trace, message());
Object.Trace(message);
}

public void Debug(string message, params object[] formatting)
{
LogMessage(LogLevel.Debug, string.Format(message,formatting));
Expand Down
10 changes: 10 additions & 0 deletions LoggingExtensions.NLog/NLogLog.cs
Expand Up @@ -17,6 +17,16 @@ public void InitializeFor(string loggerName)
_logger = LogManager.GetLogger(loggerName);
}

public void Trace(string message, params object[] formatting)
{
if (_logger.IsTraceEnabled) _logger.Log(typeof(NLogLog), new LogEventInfo(LogLevel.Trace, _logger.Name, string.Format(message, formatting)));
}

public void Trace(Func<string> message)
{
if (_logger.IsTraceEnabled) _logger.Log(typeof(NLogLog), new LogEventInfo(LogLevel.Trace, _logger.Name, message()));
}

public void Debug(string message, params object[] formatting)
{
if (_logger.IsDebugEnabled) _logger.Log(typeof(NLogLog), new LogEventInfo(LogLevel.Debug, _logger.Name, string.Format(message, formatting)));
Expand Down
13 changes: 13 additions & 0 deletions LoggingExtensions.RhinoMocks/MockLogger.cs
Expand Up @@ -8,6 +8,7 @@

public enum LogLevel
{
Trace,
Debug,
Info,
Warn,
Expand Down Expand Up @@ -44,6 +45,18 @@ public void LogMessage(LogLevel logLevel, string message)
list.Add(message);
}

public void Trace(string message, params object[] formatting)
{
LogMessage(LogLevel.Trace, string.Format(message, formatting));
_logger.Trace(message, formatting);
}

public void Trace(Func<string> message)
{
LogMessage(LogLevel.Trace, message());
_logger.Trace(message);
}

public void Debug(string message, params object[] formatting)
{
LogMessage(LogLevel.Debug, string.Format(message, formatting));
Expand Down
12 changes: 12 additions & 0 deletions LoggingExtensions.log4net/Log4NetLog.cs
Expand Up @@ -27,6 +27,18 @@ public void InitializeFor(string loggerName)
_logger = LogManager.GetLogger(loggerName);
}

[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Trace(string message, params object[] formatting)
{
if (_logger.IsTraceEnabled) Log(Level.Trace, message, formatting);
}

[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Trace(Func<string> message)
{
if (_logger.IsTraceEnabled) Log(Level.Trace, message);
}

[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Debug(string message, params object[] formatting)
{
Expand Down

0 comments on commit 420534c

Please sign in to comment.