Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performance logging level #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/Common.Logging.Core/Logging/ILog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,100 @@ public interface ILog
/// <param name="exception">The exception to log, including its stack Fatal.</param>
void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception);

/// <summary>
/// Log a message object with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
void Performance( object message );

/// <summary>
/// Log a message object with the <see cref="LogLevel.Performance"/> level including
/// the stack trace of the <see cref="Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
void Performance( object message, Exception exception );

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="args">the list of format arguments</param>
void PerformanceFormat(string format, params object[] args);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="exception">The exception to log.</param>
/// <param name="args">the list of format arguments</param>
[StringFormatMethod("format")]
void PerformanceFormat(string format, Exception exception, params object[] args);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="args"></param>
[StringFormatMethod("format")]
void PerformanceFormat(IFormatProvider formatProvider, string format, params object[] args);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="exception">The exception to log.</param>
/// <param name="args"></param>
[StringFormatMethod("format")]
void PerformanceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
void Performance(FormatMessageCallback formatMessageCallback);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
/// <param name="exception">The exception to log, including its stack trace.</param>
void Performance(FormatMessageCallback formatMessageCallback, Exception exception);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback);

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
/// <param name="exception">The exception to log, including its stack Debug.</param>
void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception);

/// <summary>
/// Checks if this logger is enabled for the <see cref="LogLevel.Trace"/> level.
/// </summary>
Expand Down Expand Up @@ -646,6 +740,14 @@ bool IsWarnEnabled
get;
}

/// <summary>
/// Checks if this logger is enabled for the <see cref="LogLevel.Performance"/> level.
/// </summary>
bool IsPerformanceEnabled
{
get;
}

/// <summary>
/// Returns the global context for variables
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions src/Common.Logging.Core/Logging/LogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,32 @@ public enum LogLevel
/// </summary>
Trace = 1,
/// <summary>
/// A performance logging level
/// </summary>
Performance = 2,
/// <summary>
/// A debug logging level
/// </summary>
Debug = 2,
Debug = 4,
/// <summary>
/// A info logging level
/// </summary>
Info = 4,
Info = 8,
/// <summary>
/// A warn logging level
/// </summary>
Warn = 8,
Warn = 16,
/// <summary>
/// An error logging level
/// </summary>
Error = 16,
Error = 32,
/// <summary>
/// A fatal logging level
/// </summary>
Fatal = 32,
Fatal = 64,
/// <summary>
/// Do not log anything.
/// </summary>
Off = 64,
Off = 128,
}
}
5 changes: 5 additions & 0 deletions src/Common.Logging.EntLib60/Logging/EntLib/EntLibLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public override bool IsWarnEnabled
get { return ShouldLog(WarningLogEntry); }
}

/// <summary>
/// Gets a value indicating whether this instance is performance enabled.
/// </summary>
public override bool IsPerformanceEnabled { get { return false; } }

/// <summary>
/// Gets a value indicating whether this instance is error enabled.
/// </summary>
Expand Down
147 changes: 147 additions & 0 deletions src/Common.Logging.Portable/Logging/Factory/AbstractLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ protected virtual WriteHandler GetWriteHandler()
/// </remarks>
public abstract bool IsWarnEnabled { get; }

/// <summary>
/// Checks if this logger is enabled for the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <remarks>
/// Override this in your derived class to comply with the underlying logging system
/// </remarks>
public abstract bool IsPerformanceEnabled { get; }

/// <summary>
/// Checks if this logger is enabled for the <see cref="LogLevel.Error"/> level.
/// </summary>
Expand Down Expand Up @@ -1058,6 +1066,145 @@ public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback

#endregion

#region Performance

/// <summary>
/// Log a message object with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="message">The message object to log.</param>
public virtual void Performance(object message)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, message, null);
}

/// <summary>
/// Log a message object with the <see cref="LogLevel.Performance"/> level including
/// the stack Fatal of the <see cref="Exception"/> passed
/// as a parameter.
/// </summary>
/// <param name="message">The message object to log.</param>
/// <param name="exception">The exception to log, including its stack Fatal.</param>
public virtual void Performance(object message, Exception exception)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, message, exception);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting Fatalrmation.</param>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="args"></param>
[StringFormatMethod("format")]
public virtual void PerformanceFormat(IFormatProvider formatProvider, string format, params object[] args)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new StringFormatFormattedMessage(formatProvider, format, args), null);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting Fatalrmation.</param>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="exception">The exception to log.</param>
/// <param name="args"></param>
[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);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="args">the list of format arguments</param>
[StringFormatMethod("format")]
public virtual void PerformanceFormat(string format, params object[] args)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new StringFormatFormattedMessage(null, format, args), null);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level.
/// </summary>
/// <param name="format">The format of the message object to log.<see cref="string.Format(string,object[])"/> </param>
/// <param name="exception">The exception to log.</param>
/// <param name="args">the list of format arguments</param>
[StringFormatMethod("format")]
public virtual void PerformanceFormat(string format, Exception exception, params object[] args)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new StringFormatFormattedMessage(null, format, args), exception);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
public virtual void Performance(FormatMessageCallback formatMessageCallback)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
/// <param name="exception">The exception to log, including its stack Fatal.</param>
public virtual void Performance(FormatMessageCallback formatMessageCallback, Exception exception)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
public virtual void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null);
}

/// <summary>
/// Log a message with the <see cref="LogLevel.Performance"/> level using a callback to obtain the message
/// </summary>
/// <remarks>
/// Using this method avoids the cost of creating a message and evaluating message arguments
/// that probably won't be logged due to loglevel settings.
/// </remarks>
/// <param name="formatProvider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
/// <param name="formatMessageCallback">A callback used by the logger to obtain the message if log level is matched</param>
/// <param name="exception">The exception to log, including its stack Fatal.</param>
public virtual void Performance(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception)
{
if (IsPerformanceEnabled)
Write(LogLevel.Performance, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception);
}

#endregion

/// <summary>
/// Returns the global context for variables
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Common.Logging.Portable/Logging/Simple/AbstractSimpleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ public override bool IsTraceEnabled
get { return IsLevelEnabled(LogLevel.Trace); }
}

/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Performance" />. If it is, only messages with a <see cref="LogLevel" /> of
/// <see cref="LogLevel.Performance" /> will be sent to <see cref="Console.Out" />.
/// </summary>
public override bool IsPerformanceEnabled
{
get { return IsLevelEnabled(LogLevel.Performance); }
}

/// <summary>
/// Returns <see langword="true" /> if the current <see cref="LogLevel" /> is greater than or
/// equal to <see cref="LogLevel.Debug" />. If it is, all messages will be sent to <see cref="Console.Out" />.
Expand Down
Loading