Using LogParser to Find Most Frequently Accessed Pages of an ASP.NET Website




Log parser is a powerful, versatile tool that a SQL-like query language to access a wide variety of text-based data sources such as log files, XML files and CSV files, as well as the Event Log, the Registry, binary files, and Active Directory. You can download LogParser here. The installer also contains samples and documentation about the different commands of Log Parser.

In this short article, we will use LogParser to parse the log file generated by IIS to find 10 most frequently accessed resource on your website. Once we have this information, we can fine tune these pages/resources to increase the overall performance of the site. The log file I am using here is from a live website and contains 3 days of data.

Step 1: Assuming your log file exists on your local machine, create an empty query file which will contain commands to access data from this log file. In this example, the query file is called top10.sql and the log file is called dnc.log. Both these files have been kept in the D: Drive of my machine.

Step 2: Open top10.sql and type the following command

Select Top 10
    cs-uri-stem as [Request URI],
    COUNT(*) AS Hits
FROM D:\dnc.log
Group by cs-uri-stem ORDER BY Hits DESC


The query is quite simple. It selects the top 10 cs-uri-stem (url’s) from the log files and groups them by the number of hits each one got in three days.

Step 3: After installing LogParser, go to Start > All Programs > LogParser. A command line window appears. Type the following command to execute the query

log-parser-command

LOGPARSER -i:IISW3C file:D:\top10.sql -o:DataGrid -q:off

Here the command -i:IISW3C signifies that we are querying the IIS W3C logs. -o:DataGrid outputs the result in a data grid.

On  executing the query, I received the following information

log-parser-output

Note: If you are thinking why did we use a .sql file in the first place instead of typing the command directly in the command window, then remember that there is a limitation of 260 characters in the command line window. Keeping the query in a separate query file helps us workaround this limitation.

This was just an example of how to use LogParser to retrieve useful performance-related information from your IIS logs. You can use it to gather information about search engines, browsers, file sizes, IP Addresses, response time and much much more.

Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Using LogParser to Find Most Frequently Accessed Pages of an ASP.NET Website"
 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions