Class ManagedColoredConsoleAppender
Appends colorful logging events to the console, using the .NET 2 built-in capabilities.
public class ManagedColoredConsoleAppender : AppenderSkeleton, IBulkAppender, IAppender, IOptionHandler
- Inheritance
-
ManagedColoredConsoleAppender
- Implements
- Inherited Members
Remarks
ManagedColoredConsoleAppender 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.
When configuring the colored console appender, mappings should be specified to map logging levels to colors. For example:
The Level is the standard log4net logging level while ForeColor and BackColor are the values of ConsoleColor enumeration.
Based on the ColoredConsoleAppender
Constructors
ManagedColoredConsoleAppender()
Initializes a new instance of the ManagedColoredConsoleAppender class.
public ManagedColoredConsoleAppender()
Remarks
The instance of the ManagedColoredConsoleAppender class is set up to write to the standard output stream.
Fields
ConsoleError
The Target to use when writing to the Console standard error output stream.
public const string ConsoleError = "Console.Error"
Field Value
Remarks
The Target to use when writing to the Console standard error output stream.
ConsoleOut
The Target to use when writing to the Console standard output stream.
public const string ConsoleOut = "Console.Out"
Field Value
Remarks
The Target to use when writing to the Console standard output stream.
Properties
RequiresLayout
This appender requires a log4net.Layout to be set.
protected override bool RequiresLayout { get; }
Property Value
- bool
true
Remarks
This appender requires a log4net.Layout to be set.
Target
Target is the value of the console output stream.
This is either "Console.Out" or "Console.Error".
public virtual string Target { get; set; }
Property Value
- string
Target is the value of the console output stream. This is either
"Console.Out"or"Console.Error".
Remarks
Target is the value of the console output stream.
This is either "Console.Out" or "Console.Error".
Methods
ActivateOptions()
Initialize the options for this appender
public override void ActivateOptions()
Remarks
Initialize the level to color mappings set on this appender.
AddMapping(LevelColors)
Add a mapping of level to color - done by the config file
public void AddMapping(ManagedColoredConsoleAppender.LevelColors mapping)
Parameters
mappingManagedColoredConsoleAppender.LevelColorsThe mapping to add
Remarks
Add a ManagedColoredConsoleAppender.LevelColors mapping to this appender. Each mapping defines the foreground and background colors for a level.
Append(LoggingEvent)
This method is called by the AppenderSkeleton.DoAppend(log4net.Core.LoggingEvent) method.
protected override void Append(LoggingEvent loggingEvent)
Parameters
loggingEventLoggingEventThe event to log.
Remarks
Writes the event to the console.
The format of the output will depend on the appender's layout.