You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2006/03/29 16:32:08 UTC
svn commit: r389802 - in /logging/log4net/trunk: src/Core/LogImpl.cs
src/ILog.cs tests/src/Core/StringFormatTest.cs
Author: nicko
Date: Wed Mar 29 06:32:04 2006
New Revision: 389802
URL: http://svn.apache.org/viewcvs?rev=389802&view=rev
Log:
Fix for LOG4NET-72. Added overloaded Format methods for 1, 2, and 3 fixed arguments. This is a performance enhancement.
Modified:
logging/log4net/trunk/src/Core/LogImpl.cs
logging/log4net/trunk/src/ILog.cs
logging/log4net/trunk/tests/src/Core/StringFormatTest.cs
Modified: logging/log4net/trunk/src/Core/LogImpl.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Core/LogImpl.cs?rev=389802&r1=389801&r2=389802&view=diff
==============================================================================
--- logging/log4net/trunk/src/Core/LogImpl.cs (original)
+++ logging/log4net/trunk/src/Core/LogImpl.cs Wed Mar 29 06:32:04 2006
@@ -223,6 +223,99 @@
/// <summary>
/// Logs a formatted message string with the <c>DEBUG</c> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void DebugFormat(string format, object arg0)
+ {
+ if (IsDebugEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>DEBUG</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void DebugFormat(string format, object arg0, object arg1)
+ {
+ if (IsDebugEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>DEBUG</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="DebugFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void DebugFormat(string format, object arg0, object arg1, object arg2)
+ {
+ if (IsDebugEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelDebug, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1, arg2 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>DEBUG</c> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -328,6 +421,99 @@
/// <summary>
/// Logs a formatted message string with the <c>INFO</c> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void InfoFormat(string format, object arg0)
+ {
+ if (IsInfoEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>INFO</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void InfoFormat(string format, object arg0, object arg1)
+ {
+ if (IsInfoEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>INFO</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="InfoFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void InfoFormat(string format, object arg0, object arg1, object arg2)
+ {
+ if (IsInfoEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelInfo, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1, arg2 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>INFO</c> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -433,6 +619,99 @@
/// <summary>
/// Logs a formatted message string with the <c>WARN</c> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void WarnFormat(string format, object arg0)
+ {
+ if (IsWarnEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>WARN</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void WarnFormat(string format, object arg0, object arg1)
+ {
+ if (IsWarnEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>WARN</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="WarnFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void WarnFormat(string format, object arg0, object arg1, object arg2)
+ {
+ if (IsWarnEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelWarn, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1, arg2 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>WARN</c> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -538,6 +817,99 @@
/// <summary>
/// Logs a formatted message string with the <c>ERROR</c> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void ErrorFormat(string format, object arg0)
+ {
+ if (IsErrorEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>ERROR</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void ErrorFormat(string format, object arg0, object arg1)
+ {
+ if (IsErrorEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>ERROR</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="ErrorFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void ErrorFormat(string format, object arg0, object arg1, object arg2)
+ {
+ if (IsErrorEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelError, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1, arg2 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>ERROR</c> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -637,6 +1009,99 @@
if (IsFatalEnabled)
{
Logger.Log(ThisDeclaringType, m_levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, args), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>FATAL</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void FatalFormat(string format, object arg0)
+ {
+ if (IsFatalEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>FATAL</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void FatalFormat(string format, object arg0, object arg1)
+ {
+ if (IsFatalEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1 }), null);
+ }
+ }
+
+ /// <summary>
+ /// Logs a formatted message string with the <c>FATAL</c> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <see cref="String.Format(IFormatProvider, string, object[])"/> method. See
+ /// <c>String.Format</c> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// The string is formatted using the <see cref="CultureInfo.InvariantCulture"/>
+ /// format provider. To specify a localized provider use the
+ /// <see cref="FatalFormat(IFormatProvider,string,object[])"/> method.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ virtual public void FatalFormat(string format, object arg0, object arg1, object arg2)
+ {
+ if (IsFatalEnabled)
+ {
+ Logger.Log(ThisDeclaringType, m_levelFatal, new SystemStringFormat(CultureInfo.InvariantCulture, format, new object[] { arg0, arg1, arg2 }), null);
}
}
Modified: logging/log4net/trunk/src/ILog.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/ILog.cs?rev=389802&r1=389801&r2=389802&view=diff
==============================================================================
--- logging/log4net/trunk/src/ILog.cs (original)
+++ logging/log4net/trunk/src/ILog.cs Wed Mar 29 06:32:04 2006
@@ -1,6 +1,6 @@
#region Copyright & License
//
-// Copyright 2001-2005 The Apache Software Foundation
+// Copyright 2001-2006 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -132,6 +132,72 @@
/// <summary>
/// Logs a formatted message string with the <see cref="Level.Debug"/> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Debug(object)"/>
+ /// <seealso cref="IsDebugEnabled"/>
+ void DebugFormat(string format, object arg0);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Debug(object)"/>
+ /// <seealso cref="IsDebugEnabled"/>
+ void DebugFormat(string format, object arg0, object arg1);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Debug(object)"/>
+ /// <seealso cref="IsDebugEnabled"/>
+ void DebugFormat(string format, object arg0, object arg1, object arg2);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -143,7 +209,7 @@
/// </para>
/// <para>
/// This method does not take an <see cref="Exception"/> object to include in the
- /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object)"/>
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
/// methods instead.
/// </para>
/// </remarks>
@@ -219,6 +285,72 @@
/// <summary>
/// Logs a formatted message string with the <see cref="Level.Info"/> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Info(object)"/>
+ /// <seealso cref="IsInfoEnabled"/>
+ void InfoFormat(string format, object arg0);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Info"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Info(object)"/>
+ /// <seealso cref="IsInfoEnabled"/>
+ void InfoFormat(string format, object arg0, object arg1);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Info"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Info(object)"/>
+ /// <seealso cref="IsInfoEnabled"/>
+ void InfoFormat(string format, object arg0, object arg1, object arg2);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Info"/> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -306,6 +438,72 @@
/// <summary>
/// Logs a formatted message string with the <see cref="Level.Warn"/> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Warn(object)"/>
+ /// <seealso cref="IsWarnEnabled"/>
+ void WarnFormat(string format, object arg0);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Warn(object)"/>
+ /// <seealso cref="IsWarnEnabled"/>
+ void WarnFormat(string format, object arg0, object arg1);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Warn(object)"/>
+ /// <seealso cref="IsWarnEnabled"/>
+ void WarnFormat(string format, object arg0, object arg1, object arg2);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -393,6 +591,72 @@
/// <summary>
/// Logs a formatted message string with the <see cref="Level.Error"/> level.
/// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Error(object)"/>
+ /// <seealso cref="IsErrorEnabled"/>
+ void ErrorFormat(string format, object arg0);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Error"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Error(object)"/>
+ /// <seealso cref="IsErrorEnabled"/>
+ void ErrorFormat(string format, object arg0, object arg1);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Error"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Error(object)"/>
+ /// <seealso cref="IsErrorEnabled"/>
+ void ErrorFormat(string format, object arg0, object arg1, object arg2);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Error"/> level.
+ /// </summary>
/// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
/// <param name="format">A String containing zero or more format items</param>
/// <param name="args">An Object array containing zero or more objects to format</param>
@@ -476,6 +740,72 @@
/// <seealso cref="Fatal(object,Exception)"/>
/// <seealso cref="IsFatalEnabled"/>
void FatalFormat(string format, params object[] args);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Fatal(object)"/>
+ /// <seealso cref="IsFatalEnabled"/>
+ void FatalFormat(string format, object arg0);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Fatal(object)"/>
+ /// <seealso cref="IsFatalEnabled"/>
+ void FatalFormat(string format, object arg0, object arg1);
+
+ /// <summary>
+ /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
+ /// </summary>
+ /// <param name="format">A String containing zero or more format items</param>
+ /// <param name="arg0">An Object to format</param>
+ /// <param name="arg1">An Object to format</param>
+ /// <param name="arg2">An Object to format</param>
+ /// <remarks>
+ /// <para>
+ /// The message is formatted using the <c>String.Format</c> method. See
+ /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
+ /// of the formatting.
+ /// </para>
+ /// <para>
+ /// This method does not take an <see cref="Exception"/> object to include in the
+ /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
+ /// methods instead.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Fatal(object)"/>
+ /// <seealso cref="IsFatalEnabled"/>
+ void FatalFormat(string format, object arg0, object arg1, object arg2);
/// <summary>
/// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
Modified: logging/log4net/trunk/tests/src/Core/StringFormatTest.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/tests/src/Core/StringFormatTest.cs?rev=389802&r1=389801&r2=389802&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Core/StringFormatTest.cs (original)
+++ logging/log4net/trunk/tests/src/Core/StringFormatTest.cs Wed Mar 29 06:32:04 2006
@@ -37,7 +37,7 @@
/// </remarks>
[TestFixture] public class StringFormatTest
{
- [Test] public void TestThreadPropertiesPattern()
+ [Test] public void TestFormatString()
{
StringAppender stringAppender = new StringAppender();
stringAppender.Layout = new PatternLayout("%message");
@@ -45,7 +45,7 @@
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
- ILog log1 = LogManager.GetLogger(rep.Name, "TestThreadProperiesPattern");
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestFormatString");
// ***
log1.Info("TestMessage");
@@ -85,11 +85,586 @@
stringAppender.Reset();
// ***
- log1.InfoFormat("Before {0} After {1} {2}", "Middle", "End");
+ log1.InfoFormat("IGNORE THIS WARNING - EXCEPTION EXPECTED Before {0} After {1} {2}", "Middle", "End");
Assert.AreEqual(STRING_FORMAT_ERROR, stringAppender.GetString(), "Test formatting error");
stringAppender.Reset();
}
- private const string STRING_FORMAT_ERROR = "<log4net.Error>Exception during StringFormat: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. <format>Before {0} After {1} {2}</format><args>{Middle, End}</args></log4net.Error>";
+ private const string STRING_FORMAT_ERROR = "<log4net.Error>Exception during StringFormat: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. <format>IGNORE THIS WARNING - EXCEPTION EXPECTED Before {0} After {1} {2}</format><args>{Middle, End}</args></log4net.Error>";
+
+
+ [Test] public void TestLogFormatApi_Debug()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Debug");
+
+ // ***
+ log1.Debug("TestMessage");
+ Assert.AreEqual("DEBUG:TestMessage", stringAppender.GetString(), "Test simple DEBUG event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Debug("TestMessage", null);
+ Assert.AreEqual("DEBUG:TestMessage", stringAppender.GetString(), "Test simple DEBUG event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Debug("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("DEBUG:TestMessageSystem.Exception: Exception message\r\n", stringAppender.GetString(), "Test simple DEBUG event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}", "1");
+ Assert.AreEqual("DEBUG:a1", stringAppender.GetString(), "Test formatted DEBUG event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("DEBUG:a1b2", stringAppender.GetString(), "Test formatted DEBUG event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("DEBUG:a1b2c3", stringAppender.GetString(), "Test formatted DEBUG event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.DebugFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("DEBUG:aQbWcEdReTf", stringAppender.GetString(), "Test formatted DEBUG event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("DEBUG:Before Middle After End", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("DEBUG:Before Middle After End", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+ [Test] public void TestLogFormatApi_NoDebug()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Threshold = Level.Info;
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Debug");
+
+ // ***
+ log1.Debug("TestMessage");
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple DEBUG event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Debug("TestMessage", null);
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple DEBUG event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Debug("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple DEBUG event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}", "1");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted DEBUG event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted DEBUG event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted DEBUG event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.DebugFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted DEBUG event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.DebugFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+
+
+ [Test] public void TestLogFormatApi_Info()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Info");
+
+ // ***
+ log1.Info("TestMessage");
+ Assert.AreEqual("INFO:TestMessage", stringAppender.GetString(), "Test simple INFO event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Info("TestMessage", null);
+ Assert.AreEqual("INFO:TestMessage", stringAppender.GetString(), "Test simple INFO event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Info("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("INFO:TestMessageSystem.Exception: Exception message\r\n", stringAppender.GetString(), "Test simple INFO event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}", "1");
+ Assert.AreEqual("INFO:a1", stringAppender.GetString(), "Test formatted INFO event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("INFO:a1b2", stringAppender.GetString(), "Test formatted INFO event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("INFO:a1b2c3", stringAppender.GetString(), "Test formatted INFO event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.InfoFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("INFO:aQbWcEdReTf", stringAppender.GetString(), "Test formatted INFO event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("INFO:Before Middle After End", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("INFO:Before Middle After End", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+ [Test] public void TestLogFormatApi_NoInfo()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Threshold = Level.Warn;
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Info");
+
+ // ***
+ log1.Info("TestMessage");
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple INFO event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Info("TestMessage", null);
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple INFO event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Info("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple INFO event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}", "1");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted INFO event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted INFO event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted INFO event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.InfoFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted INFO event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.InfoFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+
+
+ [Test] public void TestLogFormatApi_Warn()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Warn");
+
+ // ***
+ log1.Warn("TestMessage");
+ Assert.AreEqual("WARN:TestMessage", stringAppender.GetString(), "Test simple WARN event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Warn("TestMessage", null);
+ Assert.AreEqual("WARN:TestMessage", stringAppender.GetString(), "Test simple WARN event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Warn("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("WARN:TestMessageSystem.Exception: Exception message\r\n", stringAppender.GetString(), "Test simple WARN event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}", "1");
+ Assert.AreEqual("WARN:a1", stringAppender.GetString(), "Test formatted WARN event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("WARN:a1b2", stringAppender.GetString(), "Test formatted WARN event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("WARN:a1b2c3", stringAppender.GetString(), "Test formatted WARN event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.WarnFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("WARN:aQbWcEdReTf", stringAppender.GetString(), "Test formatted WARN event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("WARN:Before Middle After End", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("WARN:Before Middle After End", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+ [Test] public void TestLogFormatApi_NoWarn()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Threshold = Level.Error;
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Warn");
+
+ // ***
+ log1.Warn("TestMessage");
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple WARN event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Warn("TestMessage", null);
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple WARN event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Warn("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple WARN event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}", "1");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted WARN event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted WARN event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted WARN event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.WarnFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted WARN event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.WarnFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+
+
+ [Test] public void TestLogFormatApi_Error()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Error");
+
+ // ***
+ log1.Error("TestMessage");
+ Assert.AreEqual("ERROR:TestMessage", stringAppender.GetString(), "Test simple ERROR event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Error("TestMessage", null);
+ Assert.AreEqual("ERROR:TestMessage", stringAppender.GetString(), "Test simple ERROR event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Error("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("ERROR:TestMessageSystem.Exception: Exception message\r\n", stringAppender.GetString(), "Test simple ERROR event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}", "1");
+ Assert.AreEqual("ERROR:a1", stringAppender.GetString(), "Test formatted ERROR event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("ERROR:a1b2", stringAppender.GetString(), "Test formatted ERROR event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("ERROR:a1b2c3", stringAppender.GetString(), "Test formatted ERROR event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("ERROR:aQbWcEdReTf", stringAppender.GetString(), "Test formatted ERROR event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("ERROR:Before Middle After End", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("ERROR:Before Middle After End", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+ [Test] public void TestLogFormatApi_NoError()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Threshold = Level.Fatal;
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Error");
+
+ // ***
+ log1.Error("TestMessage");
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple ERROR event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Error("TestMessage", null);
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple ERROR event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Error("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple ERROR event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}", "1");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted ERROR event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted ERROR event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted ERROR event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.ErrorFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted ERROR event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.ErrorFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+
+
+ [Test] public void TestLogFormatApi_Fatal()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Fatal");
+
+ // ***
+ log1.Fatal("TestMessage");
+ Assert.AreEqual("FATAL:TestMessage", stringAppender.GetString(), "Test simple FATAL event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Fatal("TestMessage", null);
+ Assert.AreEqual("FATAL:TestMessage", stringAppender.GetString(), "Test simple FATAL event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Fatal("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("FATAL:TestMessageSystem.Exception: Exception message\r\n", stringAppender.GetString(), "Test simple FATAL event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}", "1");
+ Assert.AreEqual("FATAL:a1", stringAppender.GetString(), "Test formatted FATAL event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("FATAL:a1b2", stringAppender.GetString(), "Test formatted FATAL event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("FATAL:a1b2c3", stringAppender.GetString(), "Test formatted FATAL event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.FatalFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("FATAL:aQbWcEdReTf", stringAppender.GetString(), "Test formatted FATAL event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("FATAL:Before Middle After End", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("FATAL:Before Middle After End", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
+ [Test] public void TestLogFormatApi_NoFatal()
+ {
+ StringAppender stringAppender = new StringAppender();
+ stringAppender.Threshold = Level.Off;
+ stringAppender.Layout = new PatternLayout("%level:%message");
+
+ ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+ BasicConfigurator.Configure(rep, stringAppender);
+
+ ILog log1 = LogManager.GetLogger(rep.Name, "TestLogFormatApi_Fatal");
+
+ // ***
+ log1.Fatal("TestMessage");
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple FATAL event 1");
+ stringAppender.Reset();
+
+ // ***
+ log1.Fatal("TestMessage", null);
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple FATAL event 2");
+ stringAppender.Reset();
+
+ // ***
+ log1.Fatal("TestMessage", new Exception("Exception message"));
+ Assert.AreEqual("", stringAppender.GetString(), "Test simple FATAL event 3");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}", "1");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted FATAL event with 1 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}b{1}", "1", "2");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted FATAL event with 2 parm");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat("a{0}b{1}c{2}", "1", "2", "3");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted FATAL event with 3 parm");
+ stringAppender.Reset();
+
+
+ // ***
+ log1.FatalFormat("a{0}b{1}c{2}d{3}e{4}f", "Q", "W", "E", "R", "T", "Y");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatted FATAL event with 5 parms (only 4 used)");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat(null, "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with null provider");
+ stringAppender.Reset();
+
+ // ***
+ log1.FatalFormat(System.Globalization.CultureInfo.GetCultureInfo("en"), "Before {0} After {1}", "Middle", "End");
+ Assert.AreEqual("", stringAppender.GetString(), "Test formatting with 'en' provider");
+ stringAppender.Reset();
+ }
}
}