XmlLayout ClassApache log4net™ SDK Documentation
Layout that formats the log events as XML elements.
Inheritance Hierarchy

SystemObject
  log4net.LayoutLayoutSkeleton
    log4net.LayoutXmlLayoutBase
      log4net.LayoutXmlLayout

Namespace: log4net.Layout
Assembly: log4net (in log4net.dll) Version: 2.0.8.0-.NET 4.0
Syntax

public class XmlLayout : XmlLayoutBase

The XmlLayout type exposes the following members.

Constructors

  NameDescription
Public methodXmlLayout
Constructs an XmlLayout
Public methodXmlLayout(Boolean)
Constructs an XmlLayout.
Top
Properties

  NameDescription
Public propertyBase64EncodeMessage
Set whether or not to base64 encode the message.
Public propertyBase64EncodeProperties
Set whether or not to base64 encode the property values.
Public propertyContentType
Gets the content type output by this layout.
(Inherited from XmlLayoutBase.)
Public propertyFooter
The footer for the layout format.
(Inherited from LayoutSkeleton.)
Public propertyHeader
The header for the layout format.
(Inherited from LayoutSkeleton.)
Public propertyIgnoresException
Flag indicating if this layout handles exceptions
(Inherited from LayoutSkeleton.)
Public propertyInvalidCharReplacement
The string to replace characters that can not be expressed in XML with.
Remarks

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.

(Inherited from XmlLayoutBase.)
Public propertyLocationInfo
Gets a value indicating whether to include location information in the XML events.
(Inherited from XmlLayoutBase.)
Public propertyPrefix
The prefix to use for all element names
Top
Methods

  NameDescription
Public methodActivateOptions
Initialize layout options
(Overrides XmlLayoutBaseActivateOptions.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFormat(LoggingEvent)
Convenience method for easily formatting the logging event into a string variable.
(Inherited from LayoutSkeleton.)
Public methodFormat(TextWriter, LoggingEvent)
Produces a formatted string.
(Inherited from XmlLayoutBase.)
Protected methodFormatXml
Does the actual writing of the XML.
(Overrides XmlLayoutBaseFormatXml(XmlWriter, LoggingEvent).)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Remarks

The output of the XmlLayout consists of a series of log4net:event elements. It does not output a complete well-formed XML file. The output is designed to be included as an external entity in a separate file to form a correct XML file.

For example, if abc is the name of the file where the XmlLayout output goes, then a well-formed XML file would be:

<?xml version="1.0" ?>

<!DOCTYPE log4net:events SYSTEM "log4net-events.dtd" [<!ENTITY data SYSTEM "abc">]>

<log4net:events version="1.2" xmlns:log4net=http://logging.apache.orglog4net/schemaslog4net-events-1.2>
    &data;
</log4net:events>

This approach enforces the independence of the XmlLayout and the appender where it is embedded.

The version attribute helps components to correctly interpret output generated by XmlLayout. The value of this attribute should be "1.2" for release 1.2 and later.

Alternatively the Header and Footer properties can be configured to output the correct XML header, open tag and close tag. When setting the Header and Footer properties it is essential that the underlying data store not be appendable otherwise the data will become invalid XML.

See Also

Reference