?
Solved

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

Posted on 2008-10-01
5
Medium Priority
?
1,558 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

764 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