Floating FB popout byF5debug

IIS Log Parser Tool – How to query IIS log file efficiently

 

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.

image

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.

image

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.

image

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.

image

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.

image

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.

image

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

image

 

Script:

SELECT
    cs-method As Method,
    COUNT(*) As Hits
FROM '[LOGFILEPATH]'
WHERE sc-status = '302'
GROUP BY Method

image

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

image

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!!!

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Comments (1) -

newasiainconline.com
newasiainconline.com
3/29/2014 6:14:57 PM #

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.|

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter