logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: LayoutSkeleton Help
Date Thu, 15 Sep 2005 20:33:19 GMT
FYI, there is code in SVN that allows this:

<layout type="log4net.Layout.PatternLayout">
<![CDATA[
<GSIEventLog>
 <Domain>%domain</Domain>
 <ClassName>%class</ClassName>
 <RenderedMessage>%message</RenderedMessage>
 <HostName>%property{log4net:HostName}</HostName>
 <Identity>%identity</Identity>
 <LoggerName>%logger</LoggerName>
 <ThreadName>%thread</ThreadName>
 <TimeStamp>%timestamp</TimeStamp>
 <EventId>%property{EventId}</EventId>
 <Message2>%property{Message}</Message2>
 <AppUser>%property{AppUser}</AppUser>
 <SourceId>%property{SourceId}</SourceId>
</GSIEventLog>
]]>
</layout>

That may or may not be easier to read.

It looks like the %exception pattern always called ToString() on the
ExceptionObject. I wonder if people would find these useful:

 %exception{message}
 %exception{stackTrack}
 %exception{source}
 etc...

--- Jon Finley <jdf@gksys.com> wrote:

> Hi,
> 
> I have a very simple Layout based on LayoutSkeleton that generates
> XML using
> the LoggingEvent values.  However; the exception text always prints
> at the
> end of the XML.  Is there a way to turn this off?
> 
> My Format routine is as follows:
> 
>                 public override void Format(TextWriter writer,
> LoggingEvent
> loggingEvent)
>                 {
>                         writer.Write("<GSIEventLog>");
>                 writer.Write("<Domain>" + loggingEvent.Domain +
> "</Domain>");
>                     writer.Write("<ClassName>" +
> loggingEvent.LocationInformation.ClassName + "/ClassName>");
>                 writer.Write("<RenderedMessage>" +
> loggingEvent.RenderedMessage + "</message>");
>                         writer.Write("<HostName>" +
> loggingEvent.LookupProperty("log4net:HostName").ToString()  +
> "</HostName>");
>                         writer.Write("<Identity>" +
> loggingEvent.UserName +
> "</Identity>");
>                         writer.Write("<LoggerName>" +
> loggingEvent.LoggerName + "</LoggerName>");
>                         writer.Write("<ThreadName>" +
> loggingEvent.ThreadName + "</ThreadName>");
>                         writer.Write("<TimeStamp>" +
> loggingEvent.TimeStamp
> + "</TimeStamp>");
>                         writer.Write("<EventId>" +
> loggingEvent.LookupProperty("EventId").ToString() + "</EventId>");
>                         writer.Write("<Message2>" +
> loggingEvent.LookupProperty("Message").ToString() + "</Message2>");
>                         writer.Write("<AppUser>" +
> loggingEvent.LookupProperty("AppUser").ToString() + "</AppUser>");
>                         writer.Write("<SourceId>" +
> loggingEvent.LookupProperty("SourceId").ToString() + "</SourceId>");
>                 writer.Write("<ExMessage>" +
> loggingEvent.ExceptionObject.Message + "</ExMessage>");
>                     writer.Write("<ExStackTrace>" +
> loggingEvent.ExceptionObject.StackTrace + "</ExStackTrace>");
>                         writer.Write("</GSIEventLog>");
> 
>                         writer.WriteLine();
>                 }
> 
> 
> The output is:
>
<GSIEventLog><Domain>Test1.exe</Domain><ClassName>Test1.Form1/ClassName><Ren
>
deredMessage>message</message><HostName>jon-lt</HostName><Identity>GSI\jfinl
>
ey</Identity><LoggerName>Test1.Form1</LoggerName><ThreadName>2516</ThreadNam
> e><TimeStamp>9/15/2005 3:00:04
>
PM</TimeStamp><EventId>1111</EventId><Message2>message</Message2><AppUser>jf
> inley-AppUser</AppUser><SourceId></SourceId><ExMessage>Object
> reference not
> set to an instance of an object.</ExMessage><ExStackTrace>   at
> Test1.Form1.btnLog4NetTest_Click(Object sender, EventArgs e) in
> C:\Development_NET\Test\Test1\Form1.vb:line
> 236</ExStackTrace></GSIEventLog>
> System.NullReferenceException: Object reference not set to an
> instance of an
> object.
>    at Test1.Form1.btnLog4NetTest_Click(Object sender, EventArgs e) in
> C:\Development_NET\Test\Test1\Form1.vb:line 236
> 
> I would like the output to be:
>
<GSIEventLog><Domain>Test1.exe</Domain><ClassName>Test1.Form1/ClassName><Ren
>
deredMessage>message</message><HostName>jon-lt</HostName><Identity>GSI\jfinl
>
ey</Identity><LoggerName>Test1.Form1</LoggerName><ThreadName>2516</ThreadNam
> e><TimeStamp>9/15/2005 3:00:04
>
PM</TimeStamp><EventId>1111</EventId><Message2>message</Message2><AppUser>jf
> inley-AppUser</AppUser><SourceId></SourceId><ExMessage>Object
> reference not
> set to an instance of an object.</ExMessage><ExStackTrace>   at
> Test1.Form1.btnLog4NetTest_Click(Object sender, EventArgs e) in
> C:\Development_NET\Test\Test1\Form1.vb:line
> 236</ExStackTrace></GSIEventLog>
> 
> 
> Thank you,
> 
> Jon
> 
> 


Mime
View raw message