This is a short tutorial which gives how to effectively use an IIS log file to check the request and the response to keep track of the flow. Normally we use the Application logs to track the application flow, but to see the request and response we need to use the IIS logs which is basically a raw log file which will be a bit difficult for the developers to look into the request and response.
Microsoft has provided a free tool which can be used to check the log file and which is called Log Parser tool. This is a standalone unit using which we can query the log file and get the desired result using which we can analyze the application request and response. Its not limited to get the request and response but though we can use the tool to analyze the check the URI, method and many other parameters. [more]
Let us see how we can use this tool, first download the tool using the URL Log Parser, the latest version is Log Parser 2.2 is the one which is stable and can be used effectively. Once we downloaded the Log Parser executable run the application which will save the required files locally. We can use this tool directly from the Visual Studio Command Line window but for simplicity we have UI developed which can be downloaded from the URL Log Parser GUI.
Once we downloaded both the executable and installed on to the local machine now open the Log Parser GUI we can see the User Interface as shown in the screen below.
The initial screen shows the list of available script repository which can be used to query the log file. To start with first we need to get the log file of the IIS which will be available in the Inepter/Logs/ folder or any predefined path of the server. Click on the Open file button at the top ribbon of the tool as shown in the screen below.
Now select the log file from the log path, here we can select multiple files as per the requirement as shown in the screen below.
Now click on File –> New Query or by using the shortcut key Control+N which will open a new window as shown in the screen below. Here we will have a default query which can be used to query the hits count.
In the query we can see a parameter ‘[LOGFILEPATH]’ which is the file we selected initially, now hit the ! button at the top which is used to execute the query. We can see the end result in the screen itself as shown in the screen below.
We can customize the query as per the requirement and get the desired log details. If we open the raw file we will see the junk values which are not that much effective to analyze as shown in the screen below. In the log file at the top row we can see the parameter name which is very much important for us to query the log file.
Now let us write our customized query to fetch the Status Codes (Check what is a Status code here) 200 and 302 if anything available in the log file using the script below.
Script:
SELECT
cs-method As Method,
COUNT(*) As Hits
FROM ‘[LOGFILEPATH]’
WHERE sc-status = ‘200’
GROUP BY Method
Script:
SELECT
cs-method As Method,
COUNT(*) As Hits
FROM ‘[LOGFILEPATH]’
WHERE sc-status = ‘302’
GROUP BY Method
We will write one more query to check the list of available URI’s in the log file using the below script, we can see the result listed as shown in the screen below.
Script:
SELECT TOP 25
cs-uri-stem as Url,
COUNT(*) As Hits
FROM ‘[LOGFILEPATH]’
GROUP BY cs-uri-stem
ORDER By Hits DESC
We can query the log file as per the the requirement, also we can use the library scripts that are available at the front screen of the tool by just selecting the desired line and double clicking on the line will open the query window with the script. Hope this will be very useful for the developers in their day to day activities. That’s it from today, see you all in the next tutorial until then happy programming!!!
No Comments
Ahaa, its good discussion concerning this post here at this web site, I have read all that, so now me also commenting here.
Its like you read my thoughts! You appear to understand a lot about this, like you wrote the ebook in it or something. I believe that you could do with some percent to force the message house a bit, but other than that, that is great blog. An excellent read. I will definitely be back.|
Quite instructive….look onward to visiting again.|
I like what you guys are up too. This sort of clever work and exposure! Keep up the very good works guys I've included you guys to my blogroll.|