Table of Contents

Interface ILog

Namespace
log4net
Assembly
log4net.dll

The ILog interface is use by application to log messages into the log4net framework.

public interface ILog : ILoggerWrapper
Inherited Members

Examples

Simple example of logging messages

        <pre><code class="lang-csharp">ILog log = LogManager.GetLogger("application-log");

log.Info("Application Start"); log.Debug("This is a debug message");

if (log.IsDebugEnabled) { log.Debug("This is another debug message"); }

Remarks

Use the LogManager to obtain logger instances that implement this interface. The GetLogger(Assembly, Type) static method is used to get logger instances.

This class contains methods for logging at different levels and also has properties for determining if those logging levels are enabled in the current configuration.

This interface can be implemented in different ways. This documentation specifies reasonable behavior that a caller can expect from the actual implementation, however different implementations reserve the right to do things differently.

Properties

IsDebugEnabled

Checks if this logger is enabled for the Debug level.

bool IsDebugEnabled { get; }

Property Value

bool

true if this logger is enabled for Debug events, false otherwise.

Remarks

This function is intended to lessen the computational cost of disabled log debug statements.

For some ILog interface log, when you write:

log.Debug("This is entry number: " + i );

You incur the cost constructing the message, string construction and concatenation in this case, regardless of whether the message is logged or not.

If you are worried about speed (who isn't), then you should write:

if (log.IsDebugEnabled)
{ 
    log.Debug("This is entry number: " + i );
}

This way you will not incur the cost of parameter construction if debugging is disabled for log. On the other hand, if the log is debug enabled, you will incur the cost of evaluating whether the logger is debug enabled twice. Once in IsDebugEnabled and once in the Debug(object). This is an insignificant overhead since evaluating a logger takes about 1% of the time it takes to actually log. This is the preferred style of logging.

Alternatively if your logger is available statically then the is debug enabled state can be stored in a static variable like this:

private static readonly bool isDebugEnabled = log.IsDebugEnabled;

Then when you come to log you can write:

if (isDebugEnabled)
{ 
    log.Debug("This is entry number: " + i );
}

This way the debug enabled state is only queried once when the class is loaded. Using a private static readonly variable is the most efficient because it is a run time constant and can be heavily optimized by the JIT compiler.

Of course if you use a static readonly variable to hold the enabled state of the logger then you cannot change the enabled state at runtime to vary the logging that is produced. You have to decide if you need absolute speed or runtime flexibility.

See Also

IsErrorEnabled

Checks if this logger is enabled for the Error level.

bool IsErrorEnabled { get; }

Property Value

bool

true if this logger is enabled for Error events, false otherwise.

Remarks

For more information see IsDebugEnabled.

See Also

IsFatalEnabled

Checks if this logger is enabled for the Fatal level.

bool IsFatalEnabled { get; }

Property Value

bool

true if this logger is enabled for Fatal events, false otherwise.

Remarks

For more information see IsDebugEnabled.

See Also

IsInfoEnabled

Checks if this logger is enabled for the Info level.

bool IsInfoEnabled { get; }

Property Value

bool

true if this logger is enabled for Info events, false otherwise.

Remarks

For more information see IsDebugEnabled.

See Also

IsWarnEnabled

Checks if this logger is enabled for the Warn level.

bool IsWarnEnabled { get; }

Property Value

bool

true if this logger is enabled for Warn events, false otherwise.

Remarks

For more information see IsDebugEnabled.

See Also

Methods

Debug(object)

Log a message object with the Debug level.

void Debug(object message)

Parameters

message object

The message object to log.

Remarks

This method first checks if this logger is DEBUG enabled by comparing the level of this logger with the Debug level. If this logger is DEBUG enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate IObjectRenderer. 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 Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the Debug(object, Exception) form instead.

See Also

Debug(object, Exception)

Log a message object with the Debug level including the stack trace of the Exception passed as a parameter.

void Debug(object message, Exception exception)

Parameters

message object

The message object to log.

exception Exception

The exception to log, including its stack trace.

Remarks

See the Debug(object) form for more detailed information.

See Also

DebugFormat(IFormatProvider, string, params object[])

Logs a formatted message string with the Debug level.

void DebugFormat(IFormatProvider provider, string format, params object[] args)

Parameters

provider IFormatProvider

An IFormatProvider that supplies culture-specific formatting information

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Debug(object, Exception) methods instead.

See Also

DebugFormat(string, object)

Logs a formatted message string with the Debug level.

void DebugFormat(string format, object arg0)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Debug(object, Exception) methods instead.

See Also

DebugFormat(string, object, object)

Logs a formatted message string with the Debug level.

void DebugFormat(string format, object arg0, object arg1)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Debug(object, Exception) methods instead.

See Also

DebugFormat(string, object, object, object)

Logs a formatted message string with the Debug level.

void DebugFormat(string format, object arg0, object arg1, object arg2)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

arg2 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Debug(object, Exception) methods instead.

See Also

DebugFormat(string, params object[])

Logs a formatted message string with the Debug level.

void DebugFormat(string format, params object[] args)

Parameters

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Debug(object, Exception) methods instead.

See Also

Error(object)

Logs a message object with the Error level.

void Error(object message)

Parameters

message object

The message object to log.

Remarks

This method first checks if this logger is ERROR enabled by comparing the level of this logger with the Error level. If this logger is ERROR enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate IObjectRenderer. 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 Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the Error(object, Exception) form instead.

See Also

Error(object, Exception)

Log a message object with the Error level including the stack trace of the Exception passed as a parameter.

void Error(object message, Exception exception)

Parameters

message object

The message object to log.

exception Exception

The exception to log, including its stack trace.

Remarks

See the Error(object) form for more detailed information.

See Also

ErrorFormat(IFormatProvider, string, params object[])

Logs a formatted message string with the Error level.

void ErrorFormat(IFormatProvider provider, string format, params object[] args)

Parameters

provider IFormatProvider

An IFormatProvider that supplies culture-specific formatting information

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Error(object) methods instead.

See Also

ErrorFormat(string, object)

Logs a formatted message string with the Error level.

void ErrorFormat(string format, object arg0)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Error(object, Exception) methods instead.

See Also

ErrorFormat(string, object, object)

Logs a formatted message string with the Error level.

void ErrorFormat(string format, object arg0, object arg1)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Error(object, Exception) methods instead.

See Also

ErrorFormat(string, object, object, object)

Logs a formatted message string with the Error level.

void ErrorFormat(string format, object arg0, object arg1, object arg2)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

arg2 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Error(object, Exception) methods instead.

See Also

ErrorFormat(string, params object[])

Logs a formatted message string with the Error level.

void ErrorFormat(string format, params object[] args)

Parameters

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Error(object) methods instead.

See Also

Fatal(object)

Log a message object with the Fatal level.

void Fatal(object message)

Parameters

message object

The message object to log.

Remarks

This method first checks if this logger is FATAL enabled by comparing the level of this logger with the Fatal level. If this logger is FATAL enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate IObjectRenderer. 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 Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the Fatal(object, Exception) form instead.

See Also

Fatal(object, Exception)

Log a message object with the Fatal level including the stack trace of the Exception passed as a parameter.

void Fatal(object message, Exception exception)

Parameters

message object

The message object to log.

exception Exception

The exception to log, including its stack trace.

Remarks

See the Fatal(object) form for more detailed information.

See Also

FatalFormat(IFormatProvider, string, params object[])

Logs a formatted message string with the Fatal level.

void FatalFormat(IFormatProvider provider, string format, params object[] args)

Parameters

provider IFormatProvider

An IFormatProvider that supplies culture-specific formatting information

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Fatal(object) methods instead.

See Also

FatalFormat(string, object)

Logs a formatted message string with the Fatal level.

void FatalFormat(string format, object arg0)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Fatal(object, Exception) methods instead.

See Also

FatalFormat(string, object, object)

Logs a formatted message string with the Fatal level.

void FatalFormat(string format, object arg0, object arg1)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Fatal(object, Exception) methods instead.

See Also

FatalFormat(string, object, object, object)

Logs a formatted message string with the Fatal level.

void FatalFormat(string format, object arg0, object arg1, object arg2)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

arg2 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Fatal(object, Exception) methods instead.

See Also

FatalFormat(string, params object[])

Logs a formatted message string with the Fatal level.

void FatalFormat(string format, params object[] args)

Parameters

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Fatal(object) methods instead.

See Also

Info(object)

Logs a message object with the Info level.

void Info(object message)

Parameters

message object

The message object to log.

Remarks

This method first checks if this logger is INFO enabled by comparing the level of this logger with the Info level. If this logger is INFO enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate IObjectRenderer. 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 Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the Info(object, Exception) form instead.

See Also

Info(object, Exception)

Logs a message object with the INFO level including the stack trace of the Exception passed as a parameter.

void Info(object message, Exception exception)

Parameters

message object

The message object to log.

exception Exception

The exception to log, including its stack trace.

Remarks

See the Info(object) form for more detailed information.

See Also

InfoFormat(IFormatProvider, string, params object[])

Logs a formatted message string with the Info level.

void InfoFormat(IFormatProvider provider, string format, params object[] args)

Parameters

provider IFormatProvider

An IFormatProvider that supplies culture-specific formatting information

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Info(object) methods instead.

See Also

InfoFormat(string, object)

Logs a formatted message string with the Info level.

void InfoFormat(string format, object arg0)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Info(object, Exception) methods instead.

See Also

InfoFormat(string, object, object)

Logs a formatted message string with the Info level.

void InfoFormat(string format, object arg0, object arg1)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Info(object, Exception) methods instead.

See Also

InfoFormat(string, object, object, object)

Logs a formatted message string with the Info level.

void InfoFormat(string format, object arg0, object arg1, object arg2)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

arg2 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Info(object, Exception) methods instead.

See Also

InfoFormat(string, params object[])

Logs a formatted message string with the Info level.

void InfoFormat(string format, params object[] args)

Parameters

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Info(object) methods instead.

See Also

Warn(object)

Log a message object with the Warn level.

void Warn(object message)

Parameters

message object

The message object to log.

Remarks

This method first checks if this logger is WARN enabled by comparing the level of this logger with the Warn level. If this logger is WARN enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate IObjectRenderer. 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 Exception to this method will print the name of the Exception but no stack trace. To print a stack trace use the Warn(object, Exception) form instead.

See Also

Warn(object, Exception)

Log a message object with the Warn level including the stack trace of the Exception passed as a parameter.

void Warn(object message, Exception exception)

Parameters

message object

The message object to log.

exception Exception

The exception to log, including its stack trace.

Remarks

See the Warn(object) form for more detailed information.

See Also

WarnFormat(IFormatProvider, string, params object[])

Logs a formatted message string with the Warn level.

void WarnFormat(IFormatProvider provider, string format, params object[] args)

Parameters

provider IFormatProvider

An IFormatProvider that supplies culture-specific formatting information

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Warn(object) methods instead.

See Also

WarnFormat(string, object)

Logs a formatted message string with the Warn level.

void WarnFormat(string format, object arg0)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Warn(object, Exception) methods instead.

See Also

WarnFormat(string, object, object)

Logs a formatted message string with the Warn level.

void WarnFormat(string format, object arg0, object arg1)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Warn(object, Exception) methods instead.

See Also

WarnFormat(string, object, object, object)

Logs a formatted message string with the Warn level.

void WarnFormat(string format, object arg0, object arg1, object arg2)

Parameters

format string

A String containing zero or more format items

arg0 object

An Object to format

arg1 object

An Object to format

arg2 object

An Object to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Warn(object, Exception) methods instead.

See Also

WarnFormat(string, params object[])

Logs a formatted message string with the Warn level.

void WarnFormat(string format, params object[] args)

Parameters

format string

A String containing zero or more format items

args object[]

An Object array containing zero or more objects to format

Remarks

The message is formatted using the String.Format method. See Format(string, params object[]) for details of the syntax of the format string and the behavior of the formatting.

This method does not take an Exception object to include in the log event. To pass an Exception use one of the Warn(object) methods instead.

See Also

See Also