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
- Extension Methods
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 LogManager.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
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
-
Debug(object)
IsErrorEnabled
Checks if this logger is enabled for the Error level.
bool IsErrorEnabled { get; }
Property Value
Remarks
For more information see IsDebugEnabled.
- See Also
-
Error(object)
IsFatalEnabled
Checks if this logger is enabled for the Fatal level.
bool IsFatalEnabled { get; }
Property Value
Remarks
For more information see IsDebugEnabled.
- See Also
-
Fatal(object)
IsInfoEnabled
Checks if this logger is enabled for the Info level.
bool IsInfoEnabled { get; }
Property Value
Remarks
For more information see IsDebugEnabled.
- See Also
-
Info(object)
IsWarnEnabled
Checks if this logger is enabled for the Warn level.
bool IsWarnEnabled { get; }
Property Value
Remarks
For more information see IsDebugEnabled.
- See Also
-
Warn(object)
Methods
Debug(object)
Log a message object with the Debug level.
void Debug(object message)
Parameters
messageobjectThe 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)
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
messageobjectThe message object to log.
exceptionExceptionThe exception to log, including its stack trace.
Remarks
See the Debug(object) form for more detailed information.
- See Also
-
Debug(object)
DebugFormat(IFormatProvider, string, params object[])
Logs a formatted message string with the Debug level.
void DebugFormat(IFormatProvider provider, string format, params object[] args)
Parameters
providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Debug(object)
DebugFormat(string, object)
Logs a formatted message string with the Debug level.
void DebugFormat(string format, object arg0)
Parameters
Remarks
The message is formatted using the String.Format method. See
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
-
Debug(object)
DebugFormat(string, object, object)
Logs a formatted message string with the Debug level.
void DebugFormat(string format, object arg0, object arg1)
Parameters
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Debug(object)
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
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
arg2objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Debug(object)
DebugFormat(string, params object[])
Logs a formatted message string with the Debug level.
void DebugFormat(string format, params object[] args)
Parameters
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Debug(object)
Error(object)
Logs a message object with the Error level.
void Error(object message)
Parameters
messageobjectThe 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)
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
messageobjectThe message object to log.
exceptionExceptionThe exception to log, including its stack trace.
Remarks
See the Error(object) form for more detailed information.
- See Also
-
Error(object)
ErrorFormat(IFormatProvider, string, params object[])
Logs a formatted message string with the Error level.
void ErrorFormat(IFormatProvider provider, string format, params object[] args)
Parameters
providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Error(object,Exception)
ErrorFormat(string, object)
Logs a formatted message string with the Error level.
void ErrorFormat(string format, object arg0)
Parameters
Remarks
The message is formatted using the String.Format method. See
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
-
Error(object)
ErrorFormat(string, object, object)
Logs a formatted message string with the Error level.
void ErrorFormat(string format, object arg0, object arg1)
Parameters
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Error(object)
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
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
arg2objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Error(object)
ErrorFormat(string, params object[])
Logs a formatted message string with the Error level.
void ErrorFormat(string format, params object[] args)
Parameters
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Error(object,Exception)
Fatal(object)
Log a message object with the Fatal level.
void Fatal(object message)
Parameters
messageobjectThe 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)
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
messageobjectThe message object to log.
exceptionExceptionThe exception to log, including its stack trace.
Remarks
See the Fatal(object) form for more detailed information.
- See Also
-
Fatal(object)
FatalFormat(IFormatProvider, string, params object[])
Logs a formatted message string with the Fatal level.
void FatalFormat(IFormatProvider provider, string format, params object[] args)
Parameters
providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Fatal(object,Exception)
FatalFormat(string, object)
Logs a formatted message string with the Fatal level.
void FatalFormat(string format, object arg0)
Parameters
Remarks
The message is formatted using the String.Format method. See
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
-
Fatal(object)
FatalFormat(string, object, object)
Logs a formatted message string with the Fatal level.
void FatalFormat(string format, object arg0, object arg1)
Parameters
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Fatal(object)
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
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
arg2objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Fatal(object)
FatalFormat(string, params object[])
Logs a formatted message string with the Fatal level.
void FatalFormat(string format, params object[] args)
Parameters
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Fatal(object,Exception)
Info(object)
Logs a message object with the Info level.
void Info(object message)
Parameters
messageobjectThe 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)
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
messageobjectThe message object to log.
exceptionExceptionThe exception to log, including its stack trace.
Remarks
See the Info(object) form for more detailed information.
- See Also
-
Info(object)
InfoFormat(IFormatProvider, string, params object[])
Logs a formatted message string with the Info level.
void InfoFormat(IFormatProvider provider, string format, params object[] args)
Parameters
providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Info(object,Exception)
InfoFormat(string, object)
Logs a formatted message string with the Info level.
void InfoFormat(string format, object arg0)
Parameters
Remarks
The message is formatted using the String.Format method. See
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
-
Info(object)
InfoFormat(string, object, object)
Logs a formatted message string with the Info level.
void InfoFormat(string format, object arg0, object arg1)
Parameters
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Info(object)
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
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
arg2objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Info(object)
InfoFormat(string, params object[])
Logs a formatted message string with the Info level.
void InfoFormat(string format, params object[] args)
Parameters
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Info(object,Exception)
Warn(object)
Log a message object with the Warn level.
void Warn(object message)
Parameters
messageobjectThe 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)
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
messageobjectThe message object to log.
exceptionExceptionThe exception to log, including its stack trace.
Remarks
See the Warn(object) form for more detailed information.
- See Also
-
Warn(object)
WarnFormat(IFormatProvider, string, params object[])
Logs a formatted message string with the Warn level.
void WarnFormat(IFormatProvider provider, string format, params object[] args)
Parameters
providerIFormatProviderAn IFormatProvider that supplies culture-specific formatting information
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Warn(object,Exception)
WarnFormat(string, object)
Logs a formatted message string with the Warn level.
void WarnFormat(string format, object arg0)
Parameters
Remarks
The message is formatted using the String.Format method. See
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
-
Warn(object)
WarnFormat(string, object, object)
Logs a formatted message string with the Warn level.
void WarnFormat(string format, object arg0, object arg1)
Parameters
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Warn(object)
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
formatstringA String containing zero or more format items
arg0objectAn Object to format
arg1objectAn Object to format
arg2objectAn Object to format
Remarks
The message is formatted using the String.Format method. See
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
-
Warn(object)
WarnFormat(string, params object[])
Logs a formatted message string with the Warn level.
void WarnFormat(string format, params object[] args)
Parameters
formatstringA String containing zero or more format items
argsobject[]An Object array containing zero or more objects to format
Remarks
The message is formatted using the String.Format method. See
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
-
Warn(object,Exception)