Parsing output from Custom Trace Listener

Topics: Logging Application Block
Jan 7, 2009 at 12:05 AM
Hi,

I have implemented a custom trace listner as per enterprise libary guidlines.

I would like to parse the object data in Trace Data (see below)

public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
this.WriteLine(data.ToString());
}


 so that I can start to strip out the individual elements, i.e timestamp, machine etc. As currently the data looks like this:

Timestamp: 5/01/2009 4:11:03 AM
Message: Timestamp: 5/01/2009 4:11:03 AM
Message: Saved module with ID: 66f1becb-5d5b-422e-9441-48ef09c0827f
Category: General
........
i.e. all elements are separated by  a carriage return.

Obviously I can do something like

public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
Regex rgxLines = new Regex("\r\n");
string[] arrSegments = rgxLines.Split(data.ToString());
string timestamp = arrSegments[0];

this.WriteLine(data.ToString());
}


 

 

In the tracedata method, but wondered if there was some standardised way already in the Ent Lib methods?

Many Thanks

 

 

 

 
Jan 7, 2009 at 3:53 AM
Edited Jan 7, 2009 at 4:40 AM
You could also cast the data object to LogEntry.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 8, 2009 at 5:28 AM
ah of course.

Thanks Sarah