Log4net does not have a built-in mechanism for configuring the XML
output as you specified. Its very easy to write your own Layout though:
public class NaiveXmlLayout : LayoutSkeleton
{
private const string XML_FORMAT =
"<header>{0}\t<date>{1}</date>{0}\t<user>{2}</user>{0}\t<info>{3}</info>{0}</header>{0}";
override public void ActivateOptions()
{
// nop
}
override public void Format(TextWriter writer, LoggingEvent
loggingEvent)
{
writer.Write(XML_FORMAT,
Environment.NewLine, // 0
loggingEvent.TimeStamp.ToString("hh:MM:ss"), // 1
loggingEvent.UserName, // 2
loggingEvent.MessageObject); // 3
}
}
You can reference it like this:
<appender name="MyFileAppender" type="log4net.Appender.FileAppender">
<file value="Log.txt" />
<layout type="Company.Project.NaiveXmlLayout, Company.Project" />
</appender>
An improved version of that code would most likely do away with the
string format and use a XmlTextWriter instead. I'm sure there is a
better way to go about this in general. The above code is just a quick
example to show that its often trivial to make log4net do what you need
it to do.
--- "Kremer, Mark" <[EMAIL PROTECTED]> wrote:
> What exactly does the XMLLayout do? It appears that it takes the
> pattern and adds a < and > around each entire log statement. Is this
> correct? Is there a built-in way to easily output log statements in
> the format that I described below?
>
> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 13, 2005 9:55 AM
> To: Log4NET User
> Subject: Re: 1.2.9 log4net.Layout.XMLLayout
>
>
> There was a thread about this on the log4j list:
>
> http://tinyurl.com/9xusy
>
http://www.mail-archive.com/log4j-user%40logging.apache.org/msg03488.html
>
> Some possible solutions include writing your own layout or storing
> the
> data using XmlLayoutSchemaLog4j and transforming it at a later time.
> You may be able to hack together something using a PatternLayout:
>
> <date>%d</date><message>%m</message>
>
> but by the time you included all the necessary fields you'd be
> duplicating much of what XmlLayoutSchemaLog4j already does.
>
> --- "Kremer, Mark" <[EMAIL PROTECTED]> wrote:
>
> > > Are there any examples showing how to configure this layout type?
> I
> > am hoping to get an output file that would look like:
> > >
> > > <header>
> > > <date>11:33:34</date>
> > > <user>JSmith</user>
> > > <info>Blah</info>
> > > etc..
> > > </header>
> > > <header>
> > > <date>11:35:34</date>
> > > <user>JJones</user>
> > > <info>Blah again</info>
> > > etc..
> > > </header>
> > > etc...
> > >
> > > Is this possible?
> > >
> > >
> > > __________________________________________________
> > >
> > > Mark Kremer
> > > User Interface Specialist
> > > ZOLL Data Systems (formerly Pinpoint Technologies)
> > >
> > > 12202 Airport Way, Suite 300
> > > Broomfield, Colorado 80021
> > >
> > > O (303) 801-1833
> > > F (303) 801-0001
> > > www.zolldata.com
> > >
> >
>
>