Log4Net with XML output

  • Thread starter Thread starter codingx
  • Start date Start date
C

codingx

Hi

Has anyone used log4net with an XMLAppender. I need to find how to
format the xml appender so that it will create XML output. e.g

<LogEntry>
<message>"Data error" </message>
<number>"2041"</number>
</LogEntry>

I am also trying with Enterprise application logging block to achive
the above, but failed. Any help is good.

Thanks
A.K
 
Has anyone used log4net with an XMLAppender. I need to find how to
format the xml appender so that it will create XML output. e.g

<LogEntry>
<message>"Data error" </message>
<number>"2041"</number>
</LogEntry>

I am also trying with Enterprise application logging block to achive
the above, but failed. Any help is good.

There's an XmlElementLayout (or something similar). Note that the
results won't be a full XML document, because appending to that would
involve removing the document's closing tag.

I'm probably going to write a TextReader soon which will allow you to
specify multiple inputs which are read sequentially, which would make
it easier to read such a file as a simple XmlDocument.
 
Has anyone used log4net with an XMLAppender. I need to find how to
format the xml appender so that it will create XML output. e.g

<LogEntry>
<message>"Data error" </message>
<number>"2041"</number>
</LogEntry>

Try something like:

using System;
using System.Xml;

using log4net;
using log4net.Config;
using log4net.Appender;
using log4net.Layout;
using log4net.Core;

namespace E
{
public class MyXmlLayout : XmlLayoutBase
{
protected override void FormatXml(XmlWriter wrt, LoggingEvent logevt)
{
wrt.WriteStartElement("LogEntry");
wrt.WriteStartElement("Message");
wrt.WriteString(logevt.RenderedMessage);
wrt.WriteEndElement();
wrt.WriteEndElement();
}
}
}

and

<layout type="E.MyXmlLayout"/>

It is not obvious to me where the number should come from, but I
assume you will know what it is.

Arne
 
Back
Top