Solved

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

Posted on 2008-10-01
5
1,532 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now