Discussion:
Parsing XmlLayout formatted events
Simon Wallis
2004-12-02 19:53:25 UTC
Permalink
Hi, I'm using the UdpAppender to send events to another server on our network. I've got Chainsaw working for examining the events in real-time, but have also written my own app to receive the events. The events are sent to the app formatted using XmlLayout. In the app I would now like to parse the event info and insert the details into a database.

Is there an easy way to parse XmlLayout-formatted events? I was hoping for something like LoggingEvent.LoadXml() but it doesn't exist :)

Am I on my own here? If so, what would one usually do with XmlLayout-formatted events?

Thanks,
Simon.

PS. Here's a sample event formatted with XmlLayout:

<log4net:event logger="log4netTestHarness.WebForm1" timestamp="2004-12-02T14:22:09.4570099-05:00" level="FATAL" thread="30636" domain="/LM/w3svc/1/root/test/log4netTestHarness-1-127465056731440543" username="NT AUTHORITY\NETWORK SERVICE">
<log4net:message><![CDATA[This is a FATAL event.]]></log4net:message>
<log4net:properties>
<log4net:data name="log4net:HostName" value="ts1wdadesk08"/>
</log4net:properties>
<log4net:exception>Exception: System.ApplicationException Message: this is a test exception</log4net:exception>
</log4net:event>
Ron Grabowski
2004-12-04 16:39:33 UTC
Permalink
I installed Chainsaw by going to this URL:

http://logging.apache.org/log4j/docs/chainsaw.html#Installation

And clicking on the "[Launch now!]" link. It opened fine and I was able
to run the tutorial that setup 3 sample recievers.

I must admit I'm shooting in the dark here so any help would be
appreciated. I'd like to setup Chainsaw to monitor my ASP.Net
application on my local machine (and other web servers in the office)
so I don't have to keep reloading text files. In my project, I added
this appender to my log4net config file:

<appender name="UdpAppender" type="log4net.Appender.UdpAppender,
log4net">
<localPort value="8080" />
<remoteAddress value="127.0.0.1" />
<remotePort value="4560" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j, log4net" />
</appender>

I added the UdpAppender to the root logger:

<root>
<level value="DEBUG" />
<appender-ref ref="UdpAppender" />
</root>

The right most panel in Chainsaw has a treeview where the root node is
called Receivers. I right clicked on that and was presented with the
following options:

New MulticastReceiver
New SocketHubReceiver
New SocketReceiver
New UDPReceiver
New XMLSocketReceiver
New LogFilePatternReceiver

When I click on "New UDPReceiver" the program presents me with some
options for adding the new UDPReciever. I'm not able to change the
active menu item but I can change the other ones (some are prefilled
for me):

active "false"
class "class.org.apache.log4j.net.UDPReceiver"
decoder "org.apache.xml.XMLDecoder"
encoding
loggerRepository "***@1ad186f"
name "Asp.Net"
paused "false"
port 4560
threshold ALL

Have you gotten Chainsaw and log4net to work together Simon?

Thanks,
Ron
Post by Simon Wallis
Hi, I'm using the UdpAppender to send events to another server on our
network. I've got Chainsaw working for examining the events in
real-time, but have also written my own app to receive the events.
The events are sent to the app formatted using XmlLayout. In the app
I would now like to parse the event info and insert the details into
a database.
Is there an easy way to parse XmlLayout-formatted events? I was
hoping for something like LoggingEvent.LoadXml() but it doesn't exist
:)
Am I on my own here? If so, what would one usually do with
XmlLayout-formatted events?
Thanks,
Simon.
<log4net:event logger="log4netTestHarness.WebForm1"
timestamp="2004-12-02T14:22:09.4570099-05:00" level="FATAL"
thread="30636"
domain="/LM/w3svc/1/root/test/log4netTestHarness-1-127465056731440543"
Post by Simon Wallis
username="NT AUTHORITY\NETWORK SERVICE">
<log4net:message><![CDATA[This is a FATAL
event.]]></log4net:message>
<log4net:properties>
<log4net:data name="log4net:HostName" value="ts1wdadesk08"/>
</log4net:properties>
this is a test exception</log4net:exception>
</log4net:event>
Simon Wallis
2004-12-06 19:34:25 UTC
Permalink
Hi Ron, yes I got Chainsaw working. My config is almost identical. The only differences are, in log4net config, I have:

<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />

(no ", log4net") on the end, not sure what that does.

Also, I don't send events to 127.0.0.1, I use a remote IP or if running locally I use the actual IP of my machine.

And in Chainsaw UdpReceiver setup, I don't have a logger repository set, that line is blank. Other than that all is the same and it works fine.

Simon.


---------- Original Message ----------------------------------
From: Ron Grabowski <***@yahoo.com>
Reply-To: "Log4NET User" <log4net-***@logging.apache.org>
Date: Sat, 4 Dec 2004 08:39:33 -0800 (PST)
Post by Ron Grabowski
http://logging.apache.org/log4j/docs/chainsaw.html#Installation
And clicking on the "[Launch now!]" link. It opened fine and I was able
to run the tutorial that setup 3 sample recievers.
I must admit I'm shooting in the dark here so any help would be
appreciated. I'd like to setup Chainsaw to monitor my ASP.Net
application on my local machine (and other web servers in the office)
so I don't have to keep reloading text files. In my project, I added
<appender name="UdpAppender" type="log4net.Appender.UdpAppender,
log4net">
<localPort value="8080" />
<remoteAddress value="127.0.0.1" />
<remotePort value="4560" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j, log4net" />
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="UdpAppender" />
</root>
The right most panel in Chainsaw has a treeview where the root node is
called Receivers. I right clicked on that and was presented with the
New MulticastReceiver
New SocketHubReceiver
New SocketReceiver
New UDPReceiver
New XMLSocketReceiver
New LogFilePatternReceiver
When I click on "New UDPReceiver" the program presents me with some
options for adding the new UDPReciever. I'm not able to change the
active menu item but I can change the other ones (some are prefilled
active "false"
class "class.org.apache.log4j.net.UDPReceiver"
decoder "org.apache.xml.XMLDecoder"
encoding
name "Asp.Net"
paused "false"
port 4560
threshold ALL
Have you gotten Chainsaw and log4net to work together Simon?
Thanks,
Ron
Post by Simon Wallis
Hi, I'm using the UdpAppender to send events to another server on our
network. I've got Chainsaw working for examining the events in
real-time, but have also written my own app to receive the events.
The events are sent to the app formatted using XmlLayout. In the app
I would now like to parse the event info and insert the details into
a database.
Is there an easy way to parse XmlLayout-formatted events? I was
hoping for something like LoggingEvent.LoadXml() but it doesn't exist
:)
Am I on my own here? If so, what would one usually do with
XmlLayout-formatted events?
Thanks,
Simon.
<log4net:event logger="log4netTestHarness.WebForm1"
timestamp="2004-12-02T14:22:09.4570099-05:00" level="FATAL"
thread="30636"
domain="/LM/w3svc/1/root/test/log4netTestHarness-1-127465056731440543"
Post by Simon Wallis
username="NT AUTHORITY\NETWORK SERVICE">
<log4net:message><![CDATA[This is a FATAL
event.]]></log4net:message>
<log4net:properties>
<log4net:data name="log4net:HostName" value="ts1wdadesk08"/>
</log4net:properties>
this is a test exception</log4net:exception>
</log4net:event>
Ron Grabowski
2004-12-07 13:45:07 UTC
Permalink
Thanks for your reply Simon. In addition to the change you suggested, I
also searched the old mailing list at Sourceforge and discovered that I
was missing a config file for Chainsaw:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<plugin name="UDPReceiver"
class="org.apache.log4j.net.UDPReceiver">
<param name="Port" value="8080" />
</plugin>
</log4j:configuration>

Nick, I can't seem to get line numbers to appear in Chainsaw. I've
compiled my project in Debug mode. Line numbers appear fine on my other
appenders (RollingFileAppender, ADONetAppender, etc.). My UdpAppender
entry looks like this:

<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
<localPort value="80" />
<remoteAddress value="127.0.0.1" />
<remotePort value="8080" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
</appender>

Line numbers always appear as question marks in Chainsaw. Do you think
this is a log4net issue or more of a Chainsaw issue?

- Ron
Nicko Cadell
2004-12-08 11:38:30 UTC
Permalink
Post by Simon Wallis
<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
(no ", log4net") on the end, not sure what that does.
The ", log4net" postfix on the type name
"log4net.Layout.XmlLayoutSchemaLog4j, log4net" is the name of the
assembly to load the type from. This is part of the standard .NET
(Type.GetType method) type resolution system.

This is actually only a partial type name. A fully qualified type name
also includes the version, culture and public key of the assembly, for
example:

"System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"


The reason why the ", log4net" is not required for the
log4net.Layout.XmlLayoutSchemaLog4j type is that it is being loaded by
code running in the log4net assembly and this is therefore the default
assembly to look in. If the type was in any other assembly then at least
the assembly name would have to be specified.

Nicko

------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net
Nicko Cadell
2004-12-08 11:32:30 UTC
Permalink
Ron,

Be default the XmlLayoutSchemaLog4j does not include the caller location
information as it can be expensive to generate. To include it you need
to set the LocationInfo property to true on the layout, for example:

<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
<locationInfo value="true" />
</layout>

Nicko
-----Original Message-----
Sent: 07 December 2004 13:45
To: Log4NET User
Subject: Setting up Chainsaw and log4net
Thanks for your reply Simon. In addition to the change you
suggested, I also searched the old mailing list at
Sourceforge and discovered that I was missing a config file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<plugin name="UDPReceiver"
class="org.apache.log4j.net.UDPReceiver">
<param name="Port" value="8080" />
</plugin>
</log4j:configuration>
Nick, I can't seem to get line numbers to appear in Chainsaw.
I've compiled my project in Debug mode. Line numbers appear
fine on my other appenders (RollingFileAppender,
<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
<localPort value="80" />
<remoteAddress value="127.0.0.1" />
<remotePort value="8080" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
</appender>
Line numbers always appear as question marks in Chainsaw. Do
you think this is a log4net issue or more of a Chainsaw issue?
- Ron
Loading...