Index: log4net.build =================================================================== --- log4net.build (revision 1468807) +++ log4net.build (working copy) @@ -662,6 +662,7 @@ + @@ -682,6 +683,7 @@ + @@ -738,6 +740,7 @@ + @@ -757,6 +760,7 @@ + @@ -775,6 +779,7 @@ + @@ -811,6 +816,7 @@ + @@ -831,6 +837,7 @@ + @@ -850,6 +857,7 @@ + @@ -887,6 +895,7 @@ + @@ -906,6 +915,7 @@ + @@ -924,6 +934,7 @@ + Index: src/log4net.vs2008.csproj =================================================================== --- src/log4net.vs2008.csproj (revision 1468807) +++ src/log4net.vs2008.csproj (working copy) @@ -594,6 +594,9 @@ Code + + Code + Code Index: src/log4net.vs2010.csproj =================================================================== --- src/log4net.vs2010.csproj (revision 1468807) +++ src/log4net.vs2010.csproj (working copy) @@ -610,6 +610,9 @@ Code + + Code + Code @@ -784,4 +787,4 @@ - \ No newline at end of file + Index: src/Util/ILogExtensions.cs =================================================================== --- src/Util/ILogExtensions.cs (revision 0) +++ src/Util/ILogExtensions.cs (working copy) @@ -0,0 +1,1422 @@ +#region Apache License +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#endregion + +#if NET_3_5 || NET_4_0 + +using System; + +using log4net.Core; + +namespace log4net.Util +{ + /// + /// The static class ILogExtensions contains a set of widely used + /// methods that ease the interaction with the ILog interface implementations. + /// + /// + /// + /// This class contains methods for logging at different levels and checks the + /// properties for determining if those logging levels are enabled in the current + /// configuration. + /// + /// + /// Simple example of logging messages + /// + /// using log4net.Util; + /// + /// ILog log = LogManager.GetLogger("application-log"); + /// + /// log.InfoExt("Application Start"); + /// log.DebugExt("This is a debug message"); + /// + /// + public static class ILogExtensions + { + #region debug extensions + + #region debug extensions that uses log message lambda expression + + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// + /// + /// This method first checks if this logger is INFO + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is INFO enabled, then it converts + /// the message object (retrieved by invocation of the provided callback) to a + /// string by invoking the appropriate . + /// It then proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void DebugExt(this ILog logger, Func callback) + { + if (!logger.IsDebugEnabled) + return; + + logger.Debug(callback()); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void DebugExt(this ILog logger, Func callback, Exception exception) + { + if (!logger.IsDebugEnabled) + return; + + logger.Debug(callback(), exception); + } + + #endregion + + #region debug extension that use the formatter + + /// Log a message object with the level. //TODO + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// + /// + /// This method first checks if this logger is INFO + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is INFO enabled, then it converts + /// the message object (passed as parameter) to a string by invoking the appropriate + /// . It then + /// proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void DebugExt(this ILog logger, object message) + { + if (!logger.IsDebugEnabled) + return; + + logger.Debug(message); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void DebugExt(this ILog logger, object message, Exception exception) + { + if (!logger.IsDebugEnabled) + return; + + logger.Debug(message, exception); + } + + #endregion + + #region debug extension that use string format + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void DebugFormatExt(this ILog logger, string format, object arg0) + { + if (!logger.IsDebugEnabled) + return; + + logger.DebugFormat(format, arg0); + + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void DebugFormatExt(this ILog logger, string format, params object[] args) + { + if (!logger.IsDebugEnabled) + return; + + logger.DebugFormat(format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// An that supplies culture-specific formatting information + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void DebugFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args) + { + if (!logger.IsDebugEnabled) + return; + + logger.DebugFormat(provider, format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void DebugFormatExt(this ILog logger, string format, object arg0, object arg1) + { + if (!logger.IsDebugEnabled) + return; + + logger.DebugFormat(format, arg0, arg1); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void DebugFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2) + { + if (!logger.IsDebugEnabled) + return; + + logger.DebugFormat(format, arg0, arg1, arg2); + } + + #endregion + + #endregion + + #region info extensions + + #region info extensions that uses log message lambda expression + + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// + /// + /// This method first checks if this logger is INFO + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is INFO enabled, then it converts + /// the message object (retrieved by invocation of the provided callback) to a + /// string by invoking the appropriate . + /// It then proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void InfoExt(this ILog logger, Func callback) + { + if (!logger.IsInfoEnabled) + return; + + logger.Info(callback()); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void InfoExt(this ILog logger, Func callback, Exception exception) + { + if (!logger.IsInfoEnabled) + return; + + logger.Info(callback(), exception); + } + + #endregion + + #region info extension that use the formatter + + /// Log a message object with the level. //TODO + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// + /// + /// This method first checks if this logger is INFO + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is INFO enabled, then it converts + /// the message object (passed as parameter) to a string by invoking the appropriate + /// . It then + /// proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void InfoExt(this ILog logger, object message) + { + if (!logger.IsInfoEnabled) + return; + + logger.Info(message); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void InfoExt(this ILog logger, object message, Exception exception) + { + if (!logger.IsInfoEnabled) + return; + + logger.Info(message, exception); + } + + #endregion + + #region info extension that use string format + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void InfoFormatExt(this ILog logger, string format, object arg0) + { + if (!logger.IsInfoEnabled) + return; + + logger.InfoFormat(format, arg0); + + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void InfoFormatExt(this ILog logger, string format, params object[] args) + { + if (!logger.IsInfoEnabled) + return; + + logger.InfoFormat(format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// An that supplies culture-specific formatting information + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void InfoFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args) + { + if (!logger.IsInfoEnabled) + return; + + logger.InfoFormat(provider, format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void InfoFormatExt(this ILog logger, string format, object arg0, object arg1) + { + if (!logger.IsInfoEnabled) + return; + + logger.InfoFormat(format, arg0, arg1); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void InfoFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2) + { + if (!logger.IsInfoEnabled) + return; + + logger.InfoFormat(format, arg0, arg1, arg2); + } + + #endregion + + #endregion + + #region warn extensions + + #region warn extensions that uses log message lambda expression + + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// + /// + /// This method first checks if this logger is WARN + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is WARN enabled, then it converts + /// the message object (retrieved by invocation of the provided callback) to a + /// string by invoking the appropriate . + /// It then proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void WarnExt(this ILog logger, Func callback) + { + if (!logger.IsWarnEnabled) + return; + + logger.Warn(callback()); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void WarnExt(this ILog logger, Func callback, Exception exception) + { + if (!logger.IsWarnEnabled) + return; + + logger.Warn(callback(), exception); + } + + #endregion + + #region warn extension that use the formatter + + /// Log a message object with the level. //TODO + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// + /// + /// This method first checks if this logger is WARN + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is WARN enabled, then it converts + /// the message object (passed as parameter) to a string by invoking the appropriate + /// . It then + /// proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void WarnExt(this ILog logger, object message) + { + if (!logger.IsWarnEnabled) + return; + + logger.Warn(message); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void WarnExt(this ILog logger, object message, Exception exception) + { + if (!logger.IsWarnEnabled) + return; + + logger.Warn(message, exception); + } + + #endregion + + #region warn extension that use string format + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void WarnFormatExt(this ILog logger, string format, object arg0) + { + if (!logger.IsWarnEnabled) + return; + + logger.WarnFormat(format, arg0); + + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void WarnFormatExt(this ILog logger, string format, params object[] args) + { + if (!logger.IsWarnEnabled) + return; + + logger.WarnFormat(format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// An that supplies culture-specific formatting information + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void WarnFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args) + { + if (!logger.IsWarnEnabled) + return; + + logger.WarnFormat(provider, format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void WarnFormatExt(this ILog logger, string format, object arg0, object arg1) + { + if (!logger.IsWarnEnabled) + return; + + logger.WarnFormat(format, arg0, arg1); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void WarnFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2) + { + if (!logger.IsWarnEnabled) + return; + + logger.WarnFormat(format, arg0, arg1, arg2); + } + + #endregion + + #endregion + + #region error extensions + + #region error extensions that uses log message lambda expression + + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// + /// + /// This method first checks if this logger is ERROR + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is ERROR enabled, then it converts + /// the message object (retrieved by invocation of the provided callback) to a + /// string by invoking the appropriate . + /// It then proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void ErrorExt(this ILog logger, Func callback) + { + if (!logger.IsErrorEnabled) + return; + + logger.Error(callback()); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void ErrorExt(this ILog logger, Func callback, Exception exception) + { + if (!logger.IsErrorEnabled) + return; + + logger.Error(callback(), exception); + } + + #endregion + + #region error extension that use the formatter + + /// Log a message object with the level. //TODO + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// + /// + /// This method first checks if this logger is ERROR + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is ERROR enabled, then it converts + /// the message object (passed as parameter) to a string by invoking the appropriate + /// . It then + /// proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void ErrorExt(this ILog logger, object message) + { + if (!logger.IsErrorEnabled) + return; + + logger.Error(message); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void ErrorExt(this ILog logger, object message, Exception exception) + { + if (!logger.IsErrorEnabled) + return; + + logger.Error(message, exception); + } + + #endregion + + #region error extension that use string format + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void ErrorFormatExt(this ILog logger, string format, object arg0) + { + if (!logger.IsErrorEnabled) + return; + + logger.ErrorFormat(format, arg0); + + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void ErrorFormatExt(this ILog logger, string format, params object[] args) + { + if (!logger.IsErrorEnabled) + return; + + logger.ErrorFormat(format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// An that supplies culture-specific formatting information + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void ErrorFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args) + { + if (!logger.IsErrorEnabled) + return; + + logger.ErrorFormat(provider, format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void ErrorFormatExt(this ILog logger, string format, object arg0, object arg1) + { + if (!logger.IsErrorEnabled) + return; + + logger.ErrorFormat(format, arg0, arg1); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void ErrorFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2) + { + if (!logger.IsErrorEnabled) + return; + + logger.ErrorFormat(format, arg0, arg1, arg2); + } + + #endregion + + #endregion + + #region fatal extensions + + #region fatal extensions that uses log message lambda expression + + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// + /// + /// This method first checks if this logger is FATAL + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is FATAL enabled, then it converts + /// the message object (retrieved by invocation of the provided callback) to a + /// string by invoking the appropriate . + /// It then proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void FatalExt(this ILog logger, Func callback) + { + if (!logger.IsFatalEnabled) + return; + + logger.Fatal(callback()); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The lambda expression that gets the object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void FatalExt(this ILog logger, Func callback, Exception exception) + { + if (!logger.IsFatalEnabled) + return; + + logger.Fatal(callback(), exception); + } + + #endregion + + #region fatal extension that use the formatter + + /// Log a message object with the level. //TODO + /// + /// Log a message object with the level. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// + /// + /// This method first checks if this logger is FATAL + /// enabled by reading the value property. + /// This check happens always and does not depend on the + /// implementation. If this logger is FATAL enabled, then it converts + /// the message object (passed as parameter) to a string by invoking the appropriate + /// . It then + /// proceeds to call all the registered appenders in this logger + /// and also higher in the hierarchy depending on the value of + /// the additivity flag. + /// + /// WARNING Note that passing an + /// to this method will print the name of the + /// but no stack trace. To print a stack trace use the + /// form instead. + /// + /// + /// + /// + public static void FatalExt(this ILog logger, object message) + { + if (!logger.IsFatalEnabled) + return; + + logger.Fatal(message); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The logger on which the message is logged. + /// The message object to log. + /// The exception to log, including its stack trace. + /// + /// + /// See the form for more detailed information. + /// + /// + /// + /// + public static void FatalExt(this ILog logger, object message, Exception exception) + { + if (!logger.IsFatalEnabled) + return; + + logger.Fatal(message, exception); + } + + #endregion + + #region fatal extension that use string format + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void FatalFormatExt(this ILog logger, string format, object arg0) + { + if (!logger.IsFatalEnabled) + return; + + logger.FatalFormat(format, arg0); + + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void FatalFormatExt(this ILog logger, string format, params object[] args) + { + if (!logger.IsFatalEnabled) + return; + + logger.FatalFormat(format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// An that supplies culture-specific formatting information + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object array containing zero or more objects to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void FatalFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args) + { + if (!logger.IsFatalEnabled) + return; + + logger.FatalFormat(provider, format, args); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void FatalFormatExt(this ILog logger, string format, object arg0, object arg1) + { + if (!logger.IsFatalEnabled) + return; + + logger.FatalFormat(format, arg0, arg1); + } + + /// + /// Logs a formatted message string with the level. + /// + /// The logger on which the message is logged. + /// A String containing zero or more format items + /// An Object to format + /// An Object to format + /// An Object to format + /// + /// + /// The message is formatted using the String.Format method. See + /// for details of the syntax of the format string and the behavior + /// of the formatting. + /// + /// + /// This method does not take an object to include in the + /// log event. To pass an use one of the + /// methods instead. + /// + /// + /// + /// + public static void FatalFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2) + { + if (!logger.IsFatalEnabled) + return; + + logger.FatalFormat(format, arg0, arg1, arg2); + } + + #endregion + + #endregion + } +} +#endif