Table of Contents

Class TraceAppender

Namespace
log4net.Appender
Assembly
log4net.dll

Appends log events to the Trace system.

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

Remarks

The application configuration file can be used to control what listeners are actually used. See the MSDN documentation for the Trace class for details on configuring the trace system.

Events are written using the System.Diagnostics.Trace.Write(string,string) method. The event's logger name is the default value for the category parameter of the Write method.

Compact Framework
The Compact Framework does not support the Trace class for any operation except Assert. When using the Compact Framework this appender will write to the Debug system rather than the Trace system. This appender will therefore behave like the DebugAppender.

Constructors

TraceAppender()

Initializes a new instance of the TraceAppender.

public TraceAppender()

Remarks

Default constructor.

TraceAppender(ILayout)

Initializes a new instance of the TraceAppender with a specified layout.

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

Parameters

layout ILayout

The layout to use with this appender.

Remarks

Obsolete constructor.

Properties

Category

The category parameter sent to the Trace method.

public PatternLayout Category { get; set; }

Property Value

PatternLayout

Remarks

Defaults to %logger which will use the logger name of the current LoggingEvent as the category parameter.

ImmediateFlush

Gets or sets a value that indicates whether the appender will flush at the end of each write.

public bool ImmediateFlush { get; set; }

Property Value

bool

Remarks

The default behavior is to flush at the end of each write. If the option is set tofalse, then the underlying stream can defer writing to physical medium to a later time.

Avoiding the flush operation at the end of each append results in a performance gain of 10 to 20 percent. However, there is safety trade-off involved in skipping flushing. Indeed, when flushing is skipped, then it is likely that the last few log events will not be recorded on disk when the application exits. This is a high price to pay even for a 20% performance gain.

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.

Methods

Append(LoggingEvent)

Writes the logging event to the Trace system.

protected override void Append(LoggingEvent loggingEvent)

Parameters

loggingEvent LoggingEvent

The event to log.

Remarks

Writes the logging event to the Trace system.