ColoredConsoleAppender ClassApache log4net™ SDK Documentation
Appends logging events to the console.
Inheritance Hierarchy

SystemObject
  log4net.AppenderAppenderSkeleton
    log4net.AppenderColoredConsoleAppender

Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 2.0.8.0-.NET 4.0
Syntax

public class ColoredConsoleAppender : AppenderSkeleton

The ColoredConsoleAppender type exposes the following members.

Constructors

  NameDescription
Public methodColoredConsoleAppender
Initializes a new instance of the ColoredConsoleAppender class.
Public methodColoredConsoleAppender(ILayout) Obsolete.
Initializes a new instance of the ColoredConsoleAppender class with the specified layout.
Public methodColoredConsoleAppender(ILayout, Boolean) Obsolete.
Initializes a new instance of the ColoredConsoleAppender class with the specified layout.
Top
Properties

  NameDescription
Public propertyErrorHandler
Gets or sets the IErrorHandler for this appender.
(Inherited from AppenderSkeleton.)
Public propertyFilterHead
The filter chain.
(Inherited from AppenderSkeleton.)
Public propertyLayout
Gets or sets the ILayout for this appender.
(Inherited from AppenderSkeleton.)
Public propertyName
Gets or sets the name of this appender.
(Inherited from AppenderSkeleton.)
Protected propertyRequiresLayout
This appender requires a log4net.Layout to be set.
(Overrides AppenderSkeletonRequiresLayout.)
Public propertyTarget
Target is the value of the console output stream. This is either "Console.Out" or "Console.Error".
Public propertyThreshold
Gets or sets the threshold Level of this appender.
(Inherited from AppenderSkeleton.)
Top
Methods

  NameDescription
Public methodActivateOptions
Initialize the options for this appender
(Overrides AppenderSkeletonActivateOptions.)
Public methodAddFilter
Adds a filter to the end of the filter chain.
(Inherited from AppenderSkeleton.)
Public methodAddMapping
Add a mapping of level to color - done by the config file
Protected methodAppend(LoggingEvent)
Append a bulk array of logging events.
(Inherited from AppenderSkeleton.)
Protected methodAppend(LoggingEvent)
This method is called by the DoAppend(LoggingEvent) method.
(Overrides AppenderSkeletonAppend(LoggingEvent).)
Public methodClearFilters
Clears the filter list for this appender.
(Inherited from AppenderSkeleton.)
Public methodClose
Closes the appender and release resources.
(Inherited from AppenderSkeleton.)
Public methodDoAppend(LoggingEvent)
Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent)] method.
(Inherited from AppenderSkeleton.)
Public methodDoAppend(LoggingEvent)
Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent[])] method.
(Inherited from AppenderSkeleton.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFilterEvent
Test if the logging event should we output by this appender
(Inherited from AppenderSkeleton.)
Protected methodFinalize
Finalizes this appender by calling the implementation's Close method.
(Inherited from AppenderSkeleton.)
Public methodFlush
Flushes any buffered log data.
(Inherited from AppenderSkeleton.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodIsAsSevereAsThreshold
Checks if the message level is below this appender's threshold.
(Inherited from AppenderSkeleton.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnClose
Is called when the appender is closed. Derived classes should override this method if resources need to be released.
(Inherited from AppenderSkeleton.)
Protected methodPreAppendCheck
Called before [M:Append(LoggingEvent)] as a precondition.
(Inherited from AppenderSkeleton.)
Protected methodRenderLoggingEvent(LoggingEvent)
Renders the LoggingEvent to a string.
(Inherited from AppenderSkeleton.)
Protected methodRenderLoggingEvent(TextWriter, LoggingEvent)
Renders the LoggingEvent to a string.
(Inherited from AppenderSkeleton.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Fields

  NameDescription
Public fieldStatic memberConsoleError
The Target to use when writing to the Console standard error output stream.
Public fieldStatic memberConsoleOut
The Target to use when writing to the Console standard output stream.
Top
Remarks

ColoredConsoleAppender appends log events to the standard output stream or the error output stream using a layout specified by the user. It also allows the color of a specific type of message to be set.

By default, all output is written to the console's standard output stream. The Target property can be set to direct the output to the error stream.

NOTE: This appender writes directly to the application's attached console not to the System.Console.Out or System.Console.ErrorTextWriter. The System.Console.Out and System.Console.Error streams can be programmatically redirected (for example NUnit does this to capture program output). This appender will ignore these redirections because it needs to use Win32 API calls to colorize the output. To respect these redirections the ConsoleAppender must be used.

When configuring the colored console appender, mapping should be specified to map a logging level to a color. For example:

<mapping><level value="ERROR" /><foreColor value="White" /><backColor value="Red, HighIntensity" /></mapping><mapping><level value="DEBUG" /><backColor value="Green" /></mapping>

The Level is the standard log4net logging level and ForeColor and BackColor can be any combination of the following values:

  • Blue -
  • Green -
  • Red -
  • White -
  • Yellow -
  • Purple -
  • Cyan -
  • HighIntensity -

See Also

Reference