Interface ILayout
Interface implemented by layout objects
public interface ILayout
Remarks
An ILayout object is used to format a LoggingEvent as text. The Format(TextWriter,LoggingEvent) method is called by an appender to transform the LoggingEvent into a string.
The layout can also supply Header and Footer text that is appender before any events and after all the events respectively.
Properties
ContentType
The content type output by this layout.
string ContentType { get; }
Property Value
- string
The content type
Remarks
The content type output by this layout.
This is a MIME type e.g. "text/plain".
Footer
The footer for the layout format.
string Footer { get; }
Property Value
- string
the layout footer
Remarks
The Footer text will be appended after all the logging events have been formatted and appended.
Header
The header for the layout format.
string Header { get; }
Property Value
- string
the layout header
Remarks
The Header text will be appended before any logging events are formatted and appended.
IgnoresException
Flag indicating if this layout handle exceptions
bool IgnoresException { get; }
Property Value
- bool
falseif this layout handles exceptions
Remarks
If this layout handles the exception object contained within
LoggingEvent, then the layout should return
false. Otherwise, if the layout ignores the exception
object, then the layout should return true.
Methods
Format(TextWriter, LoggingEvent)
Implement this method to create your own layout format.
void Format(TextWriter writer, LoggingEvent loggingEvent)
Parameters
writerTextWriterThe TextWriter to write the formatted event to
loggingEventLoggingEventThe event to format
Remarks
This method is called by an appender to format
the loggingEvent as text and output to a writer.
If the caller does not have a TextWriter and prefers the event to be formatted as a string then the following code can be used to format the event into a StringWriter.
StringWriter writer = new StringWriter();
Layout.Format(writer, loggingEvent);
string formattedEvent = writer.ToString();