diff --git a/src/Common.Logging.Core/Logging/ILog.cs b/src/Common.Logging.Core/Logging/ILog.cs index bac96bf..d317824 100644 --- a/src/Common.Logging.Core/Logging/ILog.cs +++ b/src/Common.Logging.Core/Logging/ILog.cs @@ -598,6 +598,100 @@ public interface ILog /// The exception to log, including its stack Fatal. void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Performance( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Performance( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void PerformanceFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + [StringFormatMethod("format")] + void PerformanceFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + [StringFormatMethod("format")] + void PerformanceFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + [StringFormatMethod("format")] + void PerformanceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Performance(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Performance(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + /// /// Checks if this logger is enabled for the level. /// @@ -646,6 +740,14 @@ bool IsWarnEnabled get; } + /// + /// Checks if this logger is enabled for the level. + /// + bool IsPerformanceEnabled + { + get; + } + /// /// Returns the global context for variables /// diff --git a/src/Common.Logging.Core/Logging/LogLevel.cs b/src/Common.Logging.Core/Logging/LogLevel.cs index 41ad5de..a943b16 100644 --- a/src/Common.Logging.Core/Logging/LogLevel.cs +++ b/src/Common.Logging.Core/Logging/LogLevel.cs @@ -38,28 +38,32 @@ public enum LogLevel /// Trace = 1, /// + /// A performance logging level + /// + Performance = 2, + /// /// A debug logging level /// - Debug = 2, + Debug = 4, /// /// A info logging level /// - Info = 4, + Info = 8, /// /// A warn logging level /// - Warn = 8, + Warn = 16, /// /// An error logging level /// - Error = 16, + Error = 32, /// /// A fatal logging level /// - Fatal = 32, + Fatal = 64, /// /// Do not log anything. /// - Off = 64, + Off = 128, } } \ No newline at end of file diff --git a/src/Common.Logging.EntLib60/Logging/EntLib/EntLibLogger.cs b/src/Common.Logging.EntLib60/Logging/EntLib/EntLibLogger.cs index 4d22f42..409ce4c 100644 --- a/src/Common.Logging.EntLib60/Logging/EntLib/EntLibLogger.cs +++ b/src/Common.Logging.EntLib60/Logging/EntLib/EntLibLogger.cs @@ -135,6 +135,11 @@ public override bool IsWarnEnabled get { return ShouldLog(WarningLogEntry); } } + /// + /// Gets a value indicating whether this instance is performance enabled. + /// + public override bool IsPerformanceEnabled { get { return false; } } + /// /// Gets a value indicating whether this instance is error enabled. /// diff --git a/src/Common.Logging.Portable/Logging/Factory/AbstractLogger.cs b/src/Common.Logging.Portable/Logging/Factory/AbstractLogger.cs index 4a76a95..d8bd47f 100644 --- a/src/Common.Logging.Portable/Logging/Factory/AbstractLogger.cs +++ b/src/Common.Logging.Portable/Logging/Factory/AbstractLogger.cs @@ -200,6 +200,14 @@ protected virtual WriteHandler GetWriteHandler() /// public abstract bool IsWarnEnabled { get; } + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsPerformanceEnabled { get; } + /// /// Checks if this logger is enabled for the level. /// @@ -1058,6 +1066,145 @@ public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback #endregion + #region Performance + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Performance(object message) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Fatal of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Fatal. + public virtual void Performance(object message, Exception exception) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// + [StringFormatMethod("format")] + public virtual void PerformanceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// + [StringFormatMethod("format")] + public virtual void PerformanceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + [StringFormatMethod("format")] + public virtual void PerformanceFormat(string format, params object[] args) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + [StringFormatMethod("format")] + public virtual void PerformanceFormat(string format, Exception exception, params object[] args) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Performance(FormatMessageCallback formatMessageCallback) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Performance(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsPerformanceEnabled) + Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + /// /// Returns the global context for variables /// diff --git a/src/Common.Logging.Portable/Logging/Simple/AbstractSimpleLogger.cs b/src/Common.Logging.Portable/Logging/Simple/AbstractSimpleLogger.cs index 31806f9..bead8b9 100644 --- a/src/Common.Logging.Portable/Logging/Simple/AbstractSimpleLogger.cs +++ b/src/Common.Logging.Portable/Logging/Simple/AbstractSimpleLogger.cs @@ -209,6 +209,16 @@ public override bool IsTraceEnabled get { return IsLevelEnabled(LogLevel.Trace); } } + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// will be sent to . + /// + public override bool IsPerformanceEnabled + { + get { return IsLevelEnabled(LogLevel.Performance); } + } + /// /// Returns if the current is greater than or /// equal to . If it is, all messages will be sent to . diff --git a/src/Common.Logging.Portable/Logging/Simple/NoOpLogger.cs b/src/Common.Logging.Portable/Logging/Simple/NoOpLogger.cs index 773127c..0f26b0e 100644 --- a/src/Common.Logging.Portable/Logging/Simple/NoOpLogger.cs +++ b/src/Common.Logging.Portable/Logging/Simple/NoOpLogger.cs @@ -68,6 +68,14 @@ public bool IsWarnEnabled get { return false; } } + /// + /// Always returns . + /// + public bool IsPerformanceEnabled + { + get { return false; } + } + /// /// Always returns . /// @@ -728,7 +736,114 @@ public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMe } #endregion - + + #region Fatal + + /// + /// Ignores message. + /// + /// + public void Performance(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Performance(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void PerformanceFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void PerformanceFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void PerformanceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void PerformanceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Performance(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Performance(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + /// /// Returns the global context for variables /// diff --git a/test/Common.Logging.Tests/Logging/Factory/AbstractLoggerTests.cs b/test/Common.Logging.Tests/Logging/Factory/AbstractLoggerTests.cs index 5e4d3ae..f9f8fed 100644 --- a/test/Common.Logging.Tests/Logging/Factory/AbstractLoggerTests.cs +++ b/test/Common.Logging.Tests/Logging/Factory/AbstractLoggerTests.cs @@ -473,6 +473,14 @@ public override bool IsWarnEnabled { get { return true; } } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsPerformanceEnabled + { + get { return true; } + } } } } \ No newline at end of file