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.
Select Top 10
cs-uri-stem as [Request URI],
COUNT(*) AS Hits
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
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
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.