I have an IIS log file. And now I would need to make a C# app which will read the log file and show hits for each page. The file looks like this:

2006-04-01 00:27:12 W3SVC1 WEBPORTAL /images/menu/menu_cap_left.jpg - 34 -;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) http://sitename/ 200 0 0 222 234
The application will show page hits for each page it finds in the log file. And it will remove hits from the same user.
Does anybody have an idea how this could be done? I do not have much time.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here is my idea: Write a C# app to sort/copy the log file into the desired sequence.  Read the information.  Count.  Drop the repeats.  Write counted record.  When all counted, written, replace the original log file with the new one, or not.  If you replace you might want to sort it back to the original sequence.
mljackoAuthor Commented:
Hmm, ok, I have this log file, then I have to search line by line and check if there is a particual page in that line. If it is I add the line to an array and then check if there are duplicates. The thing is that I have no idea how to write a regular expression for this.
For example if there is this line:

2006-04-02 03:37:06 W3SVC1 WEBPORTAL GET /images/corners/top_right.gif - 80 - Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) http://SITENAME/Login.aspx?ReturnUrl=/ 222 0 0 242 233

How do I check if there is a http://SITENAME
and if there is a Login.aspx

I'm not a C# expert.  If I recall it does not have an 'instr' function(?) but it must support string indexing of some sort so you should be able to write an equivalent function, or find one already written, or something.  Bottom line appears to be that you will have to parse the record/string to isolate the piece of information that you want to work with.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

String class has a split function, so you could split it on spaces and the parse the array.  Something like this:

   string[] lineTokens=line.Split(new char[] {','})
lineTokens[0] would be date
lineTokens[1] would be time
lineTokens[4] would be is address
lineTokens[5] would be method
lineTokens[6] would be url
lineTokens[7] would be port?
lineTokens[8] would be client ip?
lineTokens[9] would be client browser?
lineTokens[10] would be URL page

If the log does NOT have the same number of tokens on each line, then you would have to search for patterns:

   int urlPos=instr.LastIndexOf("http://SITENAME");
   string urlPage=line.SubString(urlPos, line.IndexOf(' ', urlPos));  //Return last string starting with http://SITEName and ending with space
Jagadeesh MBig Data and Splunk ArchitectCommented:
Check out this code snippet...

Simple log parsing using MS Log Parser 2.2, in C#.NET

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mljackoAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.