Class AnsiColorTerminalAppender
Appends logging events to the terminal using ANSI color escape sequences.
public class AnsiColorTerminalAppender : AppenderSkeleton, IBulkAppender, IAppender, IOptionHandler
- Inheritance
-
AnsiColorTerminalAppender
- Implements
- Inherited Members
Remarks
AnsiColorTerminalAppender 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 level of message to be set.
note
This appender expects the terminal to understand the VT100 control set in order to interpret the color codes. If the terminal or console does not understand the control codes the behavior is not defined.
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 each message to the System.Console.Out or
System.Console.Error that is set at the time the event is appended.
Therefore it is possible to programmatically redirect the output of this appender
(for example NUnit does this to capture program output). While this is the desired
behavior of this appender it may have security implications in your application.
When configuring the ANSI colored terminal appender, a mapping should be specified to map a logging level to a color. For example:
The Level is the standard log4net logging level and ForeColor and BackColor can be any of the following values:
- Blue
- Green
- Red
- White
- Yellow
- Purple
- Cyan
These color values cannot be combined together to make new colors.
The attributes can be any combination of the following:
- Brightforeground is brighter
- Dimforeground is dimmer
- Underscoremessage is underlined
- Blinkforeground is blinking (does not work on all terminals)
- Reverseforeground and background are reversed
- Hiddenoutput is hidden
- Strikethroughmessage has a line through it
While any of these attributes may be combined together not all combinations work well together, for example setting both Bright and Dim attributes makes no sense.
Constructors
AnsiColorTerminalAppender()
Initializes a new instance of the AnsiColorTerminalAppender class.
public AnsiColorTerminalAppender()
Remarks
The instance of the AnsiColorTerminalAppender 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.
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
public void AddMapping(AnsiColorTerminalAppender.LevelColors mapping)
Parameters
mappingAnsiColorTerminalAppender.LevelColorsThe mapping to add
Remarks
Add a AnsiColorTerminalAppender.LevelColors mapping to this appender. Each mapping defines the foreground and background colours for a level.
Append(LoggingEvent)
This method is called by the AppenderSkeleton.DoAppend(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.