#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 using System; using System.Reflection; using log4net.Core; namespace log4net { /// /// The ILog interface is use by application to log messages into /// the log4net framework. /// /// /// /// Use the to obtain logger instances /// that implement this interface. The /// 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. /// /// /// Simple example of logging messages /// /// 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"); /// } /// /// /// /// /// Nicko Cadell /// Gert Driesen public interface ILog : ILoggerWrapper { /// Log a message object with the level. /// /// Log a message object with the level. /// /// The message object to log. /// /// /// This method first checks if this logger is DEBUG /// enabled by comparing the level of this logger with the /// level. If this logger is /// DEBUG 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. /// /// /// /// void Debug(object message); /// /// Log a message object with the level including /// the stack trace of the passed /// as a parameter. /// /// The message object to log. /// The exception to log, including its stack trace. /// /// /// See the form for more detailed information. /// /// /// /// void Debug(object message, Exception exception); /// Log a formatted string with the level. /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void DebugFormat(string format, params object[] args); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void DebugFormat(string format, object arg0); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void DebugFormat(string format, object arg0, object arg1); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void DebugFormat(string format, object arg0, object arg1, object arg2); /// /// Logs a formatted message string with the level. /// /// An that supplies culture-specific formatting information /// 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. /// /// /// /// void DebugFormat(IFormatProvider provider, string format, params object[] args); /// Log a message object with the level. /// /// Logs a message object with the level. /// /// /// /// This method first checks if this logger is INFO /// enabled by comparing the level of this logger with the /// level. 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. /// /// /// The message object to log. /// /// void Info(object message); /// /// Logs a message object with the INFO level including /// the stack trace of the passed /// as a parameter. /// /// The message object to log. /// The exception to log, including its stack trace. /// /// /// See the form for more detailed information. /// /// /// /// void Info(object message, Exception exception); /// Log a formatted message string with the level. /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void InfoFormat(string format, params object[] args); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void InfoFormat(string format, object arg0); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void InfoFormat(string format, object arg0, object arg1); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void InfoFormat(string format, object arg0, object arg1, object arg2); /// /// Logs a formatted message string with the level. /// /// An that supplies culture-specific formatting information /// 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. /// /// /// /// void InfoFormat(IFormatProvider provider, string format, params object[] args); /// Log a message object with the level. /// /// Log a message object with the level. /// /// /// /// This method first checks if this logger is WARN /// enabled by comparing the level of this logger with the /// level. 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. /// /// /// The message object to log. /// /// void Warn(object message); /// /// Log a message object with the level including /// the stack trace of the passed /// as a parameter. /// /// The message object to log. /// The exception to log, including its stack trace. /// /// /// See the form for more detailed information. /// /// /// /// void Warn(object message, Exception exception); /// Log a formatted message string with the level. /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void WarnFormat(string format, params object[] args); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void WarnFormat(string format, object arg0); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void WarnFormat(string format, object arg0, object arg1); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void WarnFormat(string format, object arg0, object arg1, object arg2); /// /// Logs a formatted message string with the level. /// /// An that supplies culture-specific formatting information /// 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. /// /// /// /// void WarnFormat(IFormatProvider provider, string format, params object[] args); /// Log a message object with the level. /// /// Logs a message object with the level. /// /// The message object to log. /// /// /// This method first checks if this logger is ERROR /// enabled by comparing the level of this logger with the /// level. 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. /// /// /// /// void Error(object message); /// /// Log a message object with the level including /// the stack trace of the passed /// as a parameter. /// /// The message object to log. /// The exception to log, including its stack trace. /// /// /// See the form for more detailed information. /// /// /// /// void Error(object message, Exception exception); /// Log a formatted message string with the level. /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void ErrorFormat(string format, params object[] args); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void ErrorFormat(string format, object arg0); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void ErrorFormat(string format, object arg0, object arg1); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void ErrorFormat(string format, object arg0, object arg1, object arg2); /// /// Logs a formatted message string with the level. /// /// An that supplies culture-specific formatting information /// 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. /// /// /// /// void ErrorFormat(IFormatProvider provider, string format, params object[] args); /// Log a message object with the level. /// /// Log a message object with the level. /// /// /// /// This method first checks if this logger is FATAL /// enabled by comparing the level of this logger with the /// level. 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. /// /// /// The message object to log. /// /// void Fatal(object message); /// /// Log a message object with the level including /// the stack trace of the passed /// as a parameter. /// /// The message object to log. /// The exception to log, including its stack trace. /// /// /// See the form for more detailed information. /// /// /// /// void Fatal(object message, Exception exception); /// Log a formatted message string with the level. /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void FatalFormat(string format, params object[] args); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void FatalFormat(string format, object arg0); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void FatalFormat(string format, object arg0, object arg1); /// /// Logs a formatted message string with the level. /// /// 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. /// /// /// /// void FatalFormat(string format, object arg0, object arg1, object arg2); /// /// Logs a formatted message string with the level. /// /// An that supplies culture-specific formatting information /// 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. /// /// /// /// void FatalFormat(IFormatProvider provider, string format, params object[] args); /// /// Checks if this logger is enabled for the level. /// /// /// true if this logger is enabled for events, false otherwise. /// /// /// /// 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 and once in /// the . 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. /// /// /// /// bool IsDebugEnabled { get; } /// /// Checks if this logger is enabled for the level. /// /// /// true if this logger is enabled for events, false otherwise. /// /// /// For more information see . /// /// /// /// bool IsInfoEnabled { get; } /// /// Checks if this logger is enabled for the level. /// /// /// true if this logger is enabled for events, false otherwise. /// /// /// For more information see . /// /// /// /// bool IsWarnEnabled { get; } /// /// Checks if this logger is enabled for the level. /// /// /// true if this logger is enabled for events, false otherwise. /// /// /// For more information see . /// /// /// /// bool IsErrorEnabled { get; } /// /// Checks if this logger is enabled for the level. /// /// /// true if this logger is enabled for events, false otherwise. /// /// /// For more information see . /// /// /// /// bool IsFatalEnabled { get; } } }