Table of Contents

Class XmlLayoutBase

Namespace
log4net.Layout
Assembly
log4net.dll

Layout that formats the log events as XML elements.

public abstract class XmlLayoutBase : LayoutSkeleton, ILayout, IOptionHandler
Inheritance
XmlLayoutBase
Implements
Derived
Inherited Members

Remarks

This is an abstract class that must be subclassed by an implementation to conform to a specific schema.

Deriving classes must implement the FormatXml(XmlWriter, LoggingEvent) method.

Constructors

XmlLayoutBase()

Protected constructor to support subclasses

protected XmlLayoutBase()

Remarks

Initializes a new instance of the XmlLayoutBase class with no location info.

XmlLayoutBase(bool)

Protected constructor to support subclasses

protected XmlLayoutBase(bool locationInfo)

Parameters

locationInfo bool

Remarks

The locationInfo parameter determines whether location information will be output by the layout. If locationInfo is set to true, then the file name and line number of the statement at the origin of the log statement will be output.

If you are embedding this layout within an SMTPAppender then make sure to set the LocationInfo option of that appender as well.

Properties

ContentType

Gets the content type output by this layout.

public override string ContentType { get; }

Property Value

string

As this is the XML layout, the value is always "text/xml".

Remarks

As this is the XML layout, the value is always "text/xml".

InvalidCharReplacement

The string to replace characters that can not be expressed in XML with.

Not all characters may be expressed in XML. This property contains the string to replace those that can not with. This defaults to a ?. Set it to the empty string to simply remove offending characters. For more details on the allowed character ranges see http://www.w3.org/TR/REC-xml/#charsets Character replacement will occur in the log message, the property names and the property values.

public string InvalidCharReplacement { get; set; }

Property Value

string

LocationInfo

Gets a value indicating whether to include location information in the XML events.

public bool LocationInfo { get; set; }

Property Value

bool

true if location information should be included in the XML events; otherwise, false.

Remarks

If LocationInfo is set to true, then the file name and line number of the statement at the origin of the log statement will be output.

If you are embedding this layout within an SMTPAppender then make sure to set the LocationInfo option of that appender as well.

Methods

ActivateOptions()

Initialize layout options

public override void ActivateOptions()

Remarks

This is part of the IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined state and must not be used.

If any of the configuration properties are modified then ActivateOptions() must be called again.

Format(TextWriter, LoggingEvent)

Produces a formatted string.

public override void Format(TextWriter writer, LoggingEvent loggingEvent)

Parameters

writer TextWriter

The TextWriter to write the formatted event to

loggingEvent LoggingEvent

The event being logged.

Remarks

Format the LoggingEvent and write it to the TextWriter.

This method creates an System.Xml.XmlTextWriter that writes to the writer. The System.Xml.XmlTextWriter is passed to the FormatXml(XmlWriter, LoggingEvent) method. Subclasses should override the FormatXml(XmlWriter, LoggingEvent) method rather than this method.

FormatXml(XmlWriter, LoggingEvent)

Does the actual writing of the XML.

protected abstract void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)

Parameters

writer XmlWriter

The writer to use to output the event to.

loggingEvent LoggingEvent

The event to write.

Remarks

Subclasses should override this method to format the LoggingEvent as XML.