#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 || MONO_3_5 || MONO_4_0 || NETSTANDARD
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 Private Static Fields
///
/// The fully qualified type of the Logger class.
///
private static readonly Type declaringType = typeof(ILogExtensions);
#endregion //Private Static Fields
#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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.Debug(callback());
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.Debug(callback(), exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.Debug(message);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.Debug(message, exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.DebugFormat(format, arg0);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.DebugFormat(format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.DebugFormat(provider, format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.DebugFormat(format, arg0, arg1);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsDebugEnabled)
return;
logger.DebugFormat(format, arg0, arg1, arg2);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.Info(callback());
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.Info(callback(), exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.Info(message);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.Info(message, exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.InfoFormat(format, arg0);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.InfoFormat(format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.InfoFormat(provider, format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.InfoFormat(format, arg0, arg1);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsInfoEnabled)
return;
logger.InfoFormat(format, arg0, arg1, arg2);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.Warn(callback());
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.Warn(callback(), exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.Warn(message);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.Warn(message, exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.WarnFormat(format, arg0);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.WarnFormat(format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.WarnFormat(provider, format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.WarnFormat(format, arg0, arg1);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsWarnEnabled)
return;
logger.WarnFormat(format, arg0, arg1, arg2);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.Error(callback());
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.Error(callback(), exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.Error(message);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.Error(message, exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.ErrorFormat(format, arg0);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.ErrorFormat(format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.ErrorFormat(provider, format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.ErrorFormat(format, arg0, arg1);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsErrorEnabled)
return;
logger.ErrorFormat(format, arg0, arg1, arg2);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.Fatal(callback());
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.Fatal(callback(), exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.Fatal(message);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.Fatal(message, exception);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.FatalFormat(format, arg0);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.FatalFormat(format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.FatalFormat(provider, format, args);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.FatalFormat(format, arg0, arg1);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
///
/// 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)
{
try
{
if (!logger.IsFatalEnabled)
return;
logger.FatalFormat(format, arg0, arg1, arg2);
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
}
}
#endregion
#endregion
}
}
#endif