Table of Contents

Class ConsoleAppender

Namespace
log4net.Appender
Assembly
log4net.dll

Appends logging events to the console.

public class ConsoleAppender : AppenderSkeleton, IBulkAppender, IAppender, IOptionHandler, IFlushable
Inheritance
ConsoleAppender
Implements
Inherited Members

Remarks

ConsoleAppender appends log events to the standard output stream or the error output stream using a layout specified by the user.

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.

Constructors

ConsoleAppender()

Initializes a new instance of the ConsoleAppender class.

public ConsoleAppender()

Remarks

The instance of the ConsoleAppender class is set up to write to the standard output stream.

ConsoleAppender(ILayout)

Initializes a new instance of the ConsoleAppender class with the specified layout.

[Obsolete("Instead use the default constructor and set the Layout property")]
public ConsoleAppender(ILayout layout)

Parameters

layout ILayout

the layout to use for this appender

Remarks

The instance of the ConsoleAppender class is set up to write to the standard output stream.

ConsoleAppender(ILayout, bool)

Initializes a new instance of the ConsoleAppender class with the specified layout.

[Obsolete("Instead use the default constructor and set the Layout & Target properties")]
public ConsoleAppender(ILayout layout, bool writeToErrorStream)

Parameters

layout ILayout

the layout to use for this appender

writeToErrorStream bool

flag set to true to write to the console error stream

Remarks

When writeToErrorStream is set to true, output is written to the standard error output stream. Otherwise, output is written 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

string

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

string

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

Append(LoggingEvent)

This method is called by the AppenderSkeleton.DoAppend(LoggingEvent) method.

protected override void Append(LoggingEvent loggingEvent)

Parameters

loggingEvent LoggingEvent

The event to log.

Remarks

Writes the event to the console.

The format of the output will depend on the appender's layout.