logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jon Finley" <...@gksys.com>
Subject LayoutSkeleton Help
Date Thu, 15 Sep 2005 20:12:37 GMT
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