Reading IIS logs using SQL

In this blog, I will show how to read IIS logs to get meaningful information using SQL like language. I would be using the free tool LogParser.
IIS logs a lot of information about each request that it processes. This information is usually stored in the C:\inetpub\logs\LogFiles folder. We can also configure the properties we want to be logged by navigating to the Logging tab of your website in IIS manager and then clicking "select fields". All the fields that can be selected are shown below:
A typical log file would contain a line which starts with #Fields:. This line will tell the sequence in which above fields are logged. You can consider this line as the table columns. Every subsequent row would be filling values in these columns. 
LogParser is the tool which allows us to read these log files by using SQL like language. I created a batch file which looks like below -
This command is telling the parser to look at IIS logs, run the sql MaxTime.sql on those logs and output the results to results.csv.
The MaxTime.sql looks like -
This sql is selecting the top 50 log entries which have highest time-taken averages. The time-taken consists of time the request was in queue, time to execute and time to client. IIS only processes a certain number of requests at any time, hence the other requests get queued. If you open the results.csv you will see something similar to the image below. I have removed the URIs.


We can create our own set of such SQLs and generate performance data based on these logs.