Permalink
Browse files

Merge pull request #12 from aalex675/master

Trace level log messages.
  • Loading branch information...
ferventcoder committed Jul 27, 2017
2 parents 9a897f3 + bfcb938 commit 420534c486ae4ea03c0ddc9a3af04079c53be383
@@ -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>
@@ -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)
{
}
@@ -8,6 +8,7 @@
public enum LogLevel
{
+ Trace,
Debug,
Info,
Warn,
@@ -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));
@@ -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)));
@@ -8,6 +8,7 @@
public enum LogLevel
{
+ Trace,
Debug,
Info,
Warn,
@@ -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));
@@ -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)
{

0 comments on commit 420534c

Please sign in to comment.