Solved

How to Use C# Regular Expressions to Parse Log File?

Posted on 2008-10-01
5
1,549 Views
Last Modified: 2012-08-13
I have an application log that I would like to parse into individual log entries that can be displayed to an end user. I have attached an actual log file along with a Word document containing  descriptions of the fields I would like to capture.

As you can see from the example, each log entry begins with a date field with the following format:[yyyy-mm-dd hh:mm:ss.ms]
The remainder of the log entry is delimited by "|" and ends at the date field of the succeeding entry. I would like to use regular expressions to split the log file into individual entries using the date field as a delimeter and for each entry I would like to capture the fields described in the example document.
The intention is for the end user to be able to sort and filter the log entries based on the caputure fields while formatting the displayed result.
So the goal is to:

1) Create a regular expression object to split the log into indivdual entries using the date field (which also needs to be captured)
2) Create a regular expression object to capture the required data from each log entry that was created as a result of the first step.

It would take me days, if not weeks to figure this out on my own. I was hoping one of the Regex gurus could provide some assistance. Many thanks!!!
tracelog.txt
Description-of-Captured-Data.doc
0
Comment
Question by:jandrews404
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 22618891
There are numerous parts to your question, but to get you started, this regex pattern worked for me:
http://www.myregextester.com/?r=340
0
 
LVL 1

Author Comment

by:jandrews404
ID: 22638127
This works perfect........I need you on retainer.
One quick question...
There is an exception message in the stack trace portion of most, but not all, of the log entries. It is always at the end and always begins with ">". Can you show me an example of how to capture this message? I've attached another document highlighting the message.

Description-of-Captured-Data.doc
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22638183
See if this matches what you need:
http://www.myregextester.com/?r=346
0
 
LVL 1

Author Closing Comment

by:jandrews404
ID: 31502128
you are the regex Master!
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22638382
Thanks for the question and the points.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question