Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Greetings C# program 17 124
send messages to whatsapp programatically 2 60
2 questions 10 29
Change to file doesn't show up 16 50
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!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

789 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