Common.Logging.Core This assembly contains the core functionality of the Common.Logging framework. In particular, checkout and for usage information. Indicates classes or members to be ignored by NCover Note, the key is chosen, because TestDriven.NET uses it as //ea argument to "Test With... Coverage" Erich Eichinger Substitute NameValueCollection in System.Collections.Specialized. Creates a new instance of NameValueCollection. Gets the values (only a single one) for the specified key (configuration name) The key. an array with one value, or null if no value exist Gets or sets the value with the specified key. The value corrsponding to the key, or null if no value exist The key. value store for the key Provides base implementation suitable for almost all logger adapters Erich Eichinger A simple logging interface abstracting logging APIs. Implementations should defer calling a message's until the message really needs to be logged to avoid performance penalties. Each log method offers to pass in a instead of the actual message. Using this style has the advantage to defer possibly expensive message argument evaluation and formatting (and formatting arguments!) until the message gets actually logged. If the message is not logged at all (e.g. due to settings), you won't have to pay the peformance penalty of creating the message. The example below demonstrates using callback style for creating the message, where the call to the and the underlying only happens, if level is enabled: Log.Debug( m=>m("result is {0}", random.NextDouble()) ); Log.Debug(delegate(m) { m("result is {0}", random.NextDouble()); }); Mark Pollack Bruno Baia Erich Eichinger Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Debug. Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Info. Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Warn. Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Error. Log a message object with the level. The message object to log. 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. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Fatal. Checks if this logger is enabled for the level. Checks if this logger is enabled for the level. Checks if this logger is enabled for the level. Checks if this logger is enabled for the level. Checks if this logger is enabled for the level. Checks if this logger is enabled for the level. Holds the method for writing a message to the log system. Creates a new logger instance using for writing log events to the underlying log system. Override this method to use a different method than for writing log events to the underlying log system. Usually you don't need to override thise method. The default implementation returns null to indicate that the default handler should be used. Actually sends the message to the underlying log system. the level of this log event. the message to log the exception to log (may be null) Log a message object with the level. The message object to log. 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. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Log a message object with the level. The message object to log. Log a message object with the level including the stack Debug of the passed as a parameter. The message object to log. The exception to log, including its stack Debug. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Debug. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Debug. Log a message object with the level. The message object to log. Log a message object with the level including the stack Info of the passed as a parameter. The message object to log. The exception to log, including its stack Info. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Info. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Info. Log a message object with the level. The message object to log. Log a message object with the level including the stack Warn of the passed as a parameter. The message object to log. The exception to log, including its stack Warn. Log a message with the level. An that supplies culture-specific formatting Warnrmation. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting Warnrmation. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Warn. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Warn. Log a message object with the level. The message object to log. Log a message object with the level including the stack Error of the passed as a parameter. The message object to log. The exception to log, including its stack Error. Log a message with the level. An that supplies culture-specific formatting Errorrmation. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting Errorrmation. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Error. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Error. Log a message object with the level. The message object to log. Log a message object with the level including the stack Fatal of the passed as a parameter. The message object to log. The exception to log, including its stack Fatal. Log a message with the level. An that supplies culture-specific formatting Fatalrmation. The format of the message object to log. Log a message with the level. An that supplies culture-specific formatting Fatalrmation. The format of the message object to log. The exception to log. Log a message with the level. The format of the message object to log. the list of format arguments Log a message with the level. The format of the message object to log. The exception to log. the list of format arguments Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Fatal. Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Log a message with the level using a callback to obtain the message Using this method avoids the cost of creating a message and evaluating message arguments that probably won't be logged due to loglevel settings. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Fatal. Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Checks if this logger is enabled for the level. Override this in your derived class to comply with the underlying logging system Format message on demand. Initializes a new instance of the class. The format message callback. Initializes a new instance of the class. The format provider. The format message callback. Calls and returns result. Format string on demand. Initializes a new instance of the class. The format provider. The message. The args. Runs on supplied arguemnts. string Represents a method responsible for writing a message to the log system. An implementation of that caches loggers handed out by this factory. Implementors just need to override . Erich Eichinger LoggerFactoryAdapter interface is used internally by LogManager Only developers wishing to write new Common.Logging adapters need to worry about this interface. Gilles Bayon Get a ILog instance by type. The type to use for the logger Get a ILog instance by key. The key of the logger Creates a new instance, the logger cache being case-sensitive. Creates a new instance, the logger cache being . Purges all loggers from cache Create the specified named logger instance Derived factories need to implement this method to create the actual logger instance. Get a ILog instance by . Usually the of the current class. An ILog instance either obtained from the internal cache or created by a call to . Get a ILog instance by key. Usually a 's Name or FullName property. An ILog instance either obtained from the internal cache or created by a call to . Get or create a ILog instance by key. Usually a 's Name or FullName property. An ILog instance either obtained from the internal cache or created by a call to . A logger created by that sends all log events to the owning adapter's Erich Eichinger Abstract class providing a standard implementation of simple loggers. Erich Eichinger Creates and initializes a the simple logger. The key, usually type key of the calling class, of the logger. The current logging threshold. Messages recieved that are beneath this threshold will not be logged. Include level in the log message. Include the current time in the log message. Include the instance key in the log message. The date and time format to use in the log message. Appends the formatted message to the specified . the that receíves the formatted message. Determines if the given log level is currently enabled. The key of the logger. Include the current log level in the log message. Include the current time in the log message. Include the instance key in the log message. The current logging threshold. Messages recieved that are beneath this threshold will not be logged. The date and time format to use in the log message. Determines Whether is set. Returns if the current is greater than or equal to . If it is, all messages will be sent to . Returns if the current is greater than or equal to . If it is, all messages will be sent to . Returns if the current is greater than or equal to . If it is, only messages with a of , , , and will be sent to . Returns if the current is greater than or equal to . If it is, only messages with a of , , and will be sent to . Returns if the current is greater than or equal to . If it is, only messages with a of and will be sent to . Returns if the current is greater than or equal to . If it is, only messages with a of will be sent to . The adapter that created this logger instance. Clears all captured events Resets the to null. Holds the list of logged events. To access this collection in a multithreaded application, put a lock on the list instance. instances send their captured log events to this method. Create a new logger instance. Create a new and send it to Holds the last log event received from any of this adapter's loggers. A logging event captured by Erich Eichinger The logger that logged this event The level used to log this event The raw message object A logged exception Create a new event instance Retrieves the formatted message text An adapter, who's loggers capture all log events and send them to . Retrieve the list of log events from . This logger factory is mainly for debugging and test purposes. This is an example how you might use this adapter for testing: // configure for capturing CapturingLoggerFactoryAdapter adapter = new CapturingLoggerFactoryAdapter(); LogManager.Adapter = adapter; // reset capture state adapter.Clear(); // log something ILog log = LogManager.GetCurrentClassLogger(); log.DebugFormat("Current Time:{0}", DateTime.Now); // check logged data Assert.AreEqual(1, adapter.LoggerEvents.Count); Assert.AreEqual(LogLevel.Debug, adapter.LastEvent.Level); Erich Eichinger Clears all captured events Resets the to null. Holds the list of logged events. To access this collection in a multithreaded application, put a lock on the list instance. instances send their captured log events to this method. Get a instance for the given type. Get a instance for the given key. Holds the last log event received from any of this adapter's loggers. The exception that is thrown when a configuration system error has occurred with Common.Logging Mark Pollack Creates a new instance of the ObjectsException class. Creates a new instance of the ConfigurationException class. with the specified message. A message about the exception. Creates a new instance of the ConfigurationException class with the specified message and root cause. A message about the exception. The root exception that is being wrapped. Implementation of that uses the standard .NET configuration APIs, ConfigurationSettings in 1.x and ConfigurationManager in 2.0 Mark Pollack Interface for basic operations to read .NET application configuration information. Provides a simple abstraction to handle BCL API differences between .NET 1.x and 2.0. Also useful for testing scenarios. Mark Pollack Parses the configuration section and returns the resulting object.

Primary purpose of this method is to allow us to parse and load configuration sections using the same API regardless of the .NET framework version.

See also System.Configuration.ConfigurationManager
Name of the configuration section. Object created by a corresponding .
Parses the configuration section and returns the resulting object. Using the System.Configuration.ConfigurationManager Name of the configuration section. Object created by a corresponding IConfigurationSectionHandler"

Primary purpose of this method is to allow us to parse and load configuration sections using the same API regardless of the .NET framework version.

This namespace contains convenience base classes for implementing your own s. Various utility methods for using during factory and logger instance configuration Erich Eichinger Initialize all members before any of this class' methods can be accessed (avoids beforeFieldInit) Adds the parser to the list of known type parsers. .NET intrinsic types are pre-registerd: short, int, long, float, double, decimal, bool Retrieves the named value from the specified . may be null the value's key if is not null, the value returned by values[key]. null otherwise. Retrieves the named value from the specified . may be null the value's key the default value, if not found if is not null, the value returned by values[key]. null otherwise. Returns the first nonnull, nonempty value among its arguments. Returns null, if the initial list was null or empty. Returns the first nonnull, nonempty value among its arguments. Also Tries parsing into an enum of the type of . the default value to return if parsing fails the string value to parse the successfully parsed value, otherwise. Tries parsing into the specified return type. the default value to return if parsing fails the string value to parse the successfully parsed value, otherwise. Throws a if is null. Throws a if is null. Throws a if an object of type is not assignable to type . Throws a if an object of type is not assignable to type . Ensures any exception thrown by the given is wrapped with an . If already throws a ConfigurationException, it will not be wrapped. the action to execute the message to be set on the thrown args to be passed to to format the message Ensures any exception thrown by the given is wrapped with an . If already throws a ConfigurationException, it will not be wrapped. the action to execute the message to be set on the thrown args to be passed to to format the message A delegate converting a string representation into the target type An anonymous action delegate with no arguments and no return value. An anonymous action delegate with no arguments and no return value. The type of method that is passed into e.g. and allows the callback method to "submit" it's message to the underlying output system. the format argument as in the argument list as in Erich Eichinger The 7 possible logging levels Gilles Bayon All logging levels A trace logging level A debug logging level A info logging level A warn logging level An error logging level A fatal logging level Do not log anything. Use the LogManager's or methods to obtain instances for logging. For configuring the underlying log system using application configuration, see the example at System.Configuration.ConfigurationManager For configuring programmatically, see the example section below. The example below shows the typical use of LogManager to obtain a reference to a logger and log an exception: ILog log = LogManager.GetLogger(this.GetType()); ... try { /* .... */ } catch(Exception ex) { log.ErrorFormat("Hi {0}", ex, "dude"); } The example below shows programmatic configuration of the underlying log system: // create properties NameValueCollection properties = new NameValueCollection(); properties["showDateTime"] = "true"; // set Adapter Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); Gilles Bayon The key of the default configuration section to read settings from. You can always change the source of your configuration settings by setting another instance on . Performs static 1-time init of LogManager by calling Reset the infrastructure to its default settings. This means, that configuration settings will be re-read from section <common/logging> of your app.config. This is mainly used for unit testing, you wouldn't normally use this in your applications.
Note: instances already handed out from this LogManager are not(!) affected. Resetting LogManager only affects new instances being handed out.
Reset the infrastructure to its default settings. This means, that configuration settings will be re-read from section <common/logging> of your app.config. This is mainly used for unit testing, you wouldn't normally use this in your applications.
Note: instances already handed out from this LogManager are not(!) affected. Resetting LogManager only affects new instances being handed out.
the instance to obtain settings for re-initializing the LogManager.
Gets the logger by calling on the currently configured using the type of the calling class. This method needs to inspect the in order to determine the calling class. This of course comes with a performance penalty, thus you shouldn't call it too often in your application. the logger instance obtained from the current Cache the function returned from CreateGetClassNameFunction Creates a function which creates a new StackFrame and get the Method 3 (2 from the callee's perspective) steps up in the callstack A function, returning the calling the Method invoking the function System.Diagnostics.StackFrame does not exist on the platform (ex. windows phone) or StackFrame(int skipFrames) constructor not present or StackFrame.GetMethod() not present Gets the logger by calling on the currently configured using the specified type. the logger instance obtained from the current Gets the logger by calling on the currently configured using the specified type. The type. the logger instance obtained from the current Gets the logger by calling on the currently configured using the specified key. The key. the logger instance obtained from the current Builds the logger factory adapter. a factory adapter instance. Is never null. Builds a instance from the given using . the instance. Is never null Gets the configuration reader used to initialize the LogManager. Primarily used for testing purposes but maybe useful to obtain configuration information from some place other than the .NET application configuration file. The configuration reader. Gets or sets the adapter. The adapter. Container used to hold configuration information from config file. Gilles Bayon The type that will be used for creating Additional user supplied properties that are passed to the 's constructor. The type that will be used for creating instances. Additional user supplied properties that are passed to the 's constructor. This namespace contains all core classes making up the Common.Logging framework. This namespace contains portable out-of-the-box adapters, namely and the all output suppressing . For unit testing, you may also want to have a look at that allows to easily inspect logged messages. This namespace contains various utility classes. Base factory implementation for creating simple instances. Default settings are LogLevel.All, showDateTime = true, showLogName = true, and no DateTimeFormat. The keys in the NameValueCollection to configure this adapter are the following level showDateTime showLogName dateTimeFormat Here is an example how to implement your own logging adapter: public class ConsoleOutLogger : AbstractSimpleLogger { public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) { } protected override void WriteInternal(LogLevel level, object message, Exception e) { // Use a StringBuilder for better performance StringBuilder sb = new StringBuilder(); FormatOutput(sb, level, message, e); // Print to the appropriate destination Console.Out.WriteLine(sb.ToString()); } } public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter { public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) : base(properties) { } protected override ILog CreateLogger(string key, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) { ILog log = new ConsoleOutLogger(key, level, showLevel, showDateTime, showLogName, dateTimeFormat); return log; } } Gilles Bayon Mark Pollack Erich Eichinger Initializes a new instance of the class. Looks for level, showDateTime, showLogName, dateTimeFormat items from for use when the GetLogger methods are called. System.Configuration.ConfigurationManager for more information on how to use the standard .NET application configuraiton file (App.config/Web.config) to configure this adapter. The key value collection, typically specified by the user in a configuration section named common/logging. Initializes a new instance of the class with default settings for the loggers created by this factory. Create the specified logger instance Derived factories need to implement this method to create the actual logger instance. a new logger instance. Must never be null! The default to use when creating new instances. The default setting to use when creating new instances. The default setting to use when creating new instances. The default setting to use when creating new instances. The default setting to use when creating new instances.

Overview

There are a variety of logging implementations for .NET currently in use, log4net, Enterprise Library Logging, NLog, to key the most popular. The downside of having differerent implementation is that they do not share a common interface and therefore impose a particular logging implementation on the users of your library. To solve this dependency problem the Common.Logging library introduces a simple abstraction to allow you to select a specific logging implementation at runtime. The library is based on work done by the developers of IBatis.NET and it's usage is inspired by log4net. Many thanks to the developers of those projects!

Usage

The core logging library Common.Logging provides the base logging interface as well as the global that you use to instrument your code: ILog log = LogManager.GetLogger(this.GetType()); log.DebugFormat("Hi {0}", "dude"); To output the information logged, you need to tell Common.Logging, what underlying logging system to use. Common.Logging already includes simple console and trace based logger implementations usable out of the box. Adding the following configuration snippet to your app.config causes Common.Logging to output all information to the console: <configuration> <configSections> <sectionGroup key="common"> <section key="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> <arg key="level" value="DEBUG" /> </factoryAdapter> </logging> </common> </configuration>

Customizing

In the case you want to integrate your own logging system that is not supported by Common.Logging yet, it is easily possible to implement your own plugin by implementing . For convenience there is a base implementation available that usually makes implementing your own adapter a breeze.

<system.diagnostics> Integration

If your code already uses the .NET framework's built-in System.Diagnostics.Trace system, you can use CommonLoggingTraceListener in Common.Logging to redirect all trace output to the Common.Logging infrastructure.
Sends log messages to . Gilles Bayon Creates and initializes a logger that writes messages to . The key, usually type key of the calling class, of the logger. The current logging threshold. Messages recieved that are beneath this threshold will not be logged. Include the current log level in the log message. Include the current time in the log message. Include the instance key in the log message. The date and time format to use in the log message. Do the actual logging by constructing the log message using a then sending the output to . The of the message. The log message. An optional associated with the message. Factory for creating instances that write data using . Below is an example how to configure this adapter: <configuration> <configSections> <sectionGroup key="common"> <section key="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" /> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Simple.DebugLoggerFactoryAdapter, Common.Logging"> <arg key="level" value="ALL" /> </factoryAdapter> </logging> </common> </configuration> Gilles Bayon Mark Pollack Erich Eichinger Initializes a new instance of the class using default settings. Initializes a new instance of the class. Looks for level, showDateTime, showLogName, dateTimeFormat items from for use when the GetLogger methods are called. for more information on how to use the standard .NET application configuraiton file (App.config/Web.config) to configure this adapter. The key value collection, typically specified by the user in a configuration section named common/logging. Initializes a new instance of the class with default settings for the loggers created by this factory. Creates a new instance. Silently ignores all log messages. Gilles Bayon Erich Eichinger Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack trace. Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Debug. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Debug. Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting information. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Info. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Info. Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Warnrmation. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Warnrmation. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Warn. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Warn. Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Errorrmation. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Errorrmation. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Error. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Error. Ignores message. Ignores message. Ignores message. The format of the message object to log. Ignores message. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Fatalrmation. The format of the message object to log. the list of message format arguments Ignores message. An that supplies culture-specific formatting Fatalrmation. The format of the message object to log. The exception to log. the list of message format arguments Ignores message. A callback used by the logger to obtain the message if log level is matched Ignores message. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Fatal. Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched Ignores message. An that supplies culture-specific formatting information. A callback used by the logger to obtain the message if log level is matched The exception to log, including its stack Fatal. Always returns . Always returns . Always returns . Always returns . Always returns . Always returns . Factory for creating instances that silently ignores logging requests. This logger adapter is the default used by Common.Logging if unconfigured. Using this logger adapter is the most efficient way to suppress any logging output. Below is an example how to configure this adapter: <configuration> <configSections> <sectionGroup key="common"> <section key="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" /> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging"> <arg key="level" value="ALL" /> </factoryAdapter> </logging> </common> </configuration> Gilles Bayon Constructor Constructor Get a ILog instance by type Get a ILog instance by type key