tags:

views:

180

answers:

4

A lot of programs log things into a text file in a format something like this:

11/19/2008 13:29:01 DEBUG Opening connection to localhost.

11/19/2008 13:29:01 DEBUG Sending login message for user 'ADMIN'.

11/19/2008 13:29:03 DEBUG Received login response 'OK' for user 'ADMIN'.

...

However, I prefer something more structured like XML so I can parse the logs more easily. I've been doing this in my VB6 / Asp Classic programs for years and I want to do it in .Net now. Is there anything out there that will do this already or should I just re-write my VB6 code in C#?

Here is how a call to my logging component looks for my VB6 programs:

Trace.Warn "MMain", "Main(command, other data)", "Deprecated command", _
    sCommandName, sOtherData

resulting in the following log entry:

<Info time="11/17/2008 04:49:45 PM" mod="MMain" proc="Main" entry="Deprecated command" command="The_Bad_Command" other_data="The other data." />

When I want to open the log with my custom log viewer, I simply wrap the whole file in a root node, and then I can easily do this using MSXML to filter the entries that I'm seeing, find a specific user's login, etc. etc...

<Log>
...the log file text...
</Log>
+1  A: 

I'm not sure of any products that do that, but you could use log4net and write your own appender (output handler).

Robert Wagner
A: 

Enteprise library Logging block provides different loggings formats such as xml but it is a long way to configure and deal with it

Oscar Cabrero
A: 

There is no library that does what I want. I made one myself.

wizlb
A: 

Both log4j and logback have XMLLayouts which can generate XML fragments, which can then be postprocessed by Apache Chainsaw or Lillith.

Thorbjørn Ravn Andersen