---
title: "Tip: Microsoft LogParser [Studio] superfast SQL-like querying of any log file"
url: https://knowledge-base.havit.eu/2017/11/28/tip-microsoft-logparser-studio-superfast-sql-like-querying-of-any-log-file/
date: 2017-11-28
author: "Robert Haken"
topics: ["Database", "Development Tools", "IT Stuff"]
tags: ["LogParser"]
source: HAVIT Knowledge Base
---

# Tip: Microsoft LogParser [Studio] superfast SQL-like querying of any log file
[LogParser](https://technet.microsoft.com/en-us/scriptcenter/dd919274.aspx) ([download](https://www.microsoft.com/en-us/download/details.aspx?id=24659)) is a command line tool from Microsoft which allows you to query any text-based log file using SQL-like syntax. The basic list of supported formats is quite impressive: IISW3C, NCSA, IIS, IISODBC, BIN, IISMSID, HTTPERR, URLSCAN, CSV, TSV, W3C, XML, EVT, ETW, NETMON, REG, ADS, TEXTLINE, TEXTWORD, FS and COM.

I usually use it for querying IIS Log files and believe me it is super-fast. On my [Lenovo X1 i7/16GB/SSD](http://psref.lenovo.com/Detail/ThinkPad_X1_Carbon_4th_Gen?M=20FC0038%2B%2B) it was able to query 8.97GB of log files 2min 12sec!

[code lang=”text” light=”true”]
 SELECT
 Date,
 TO_INT(COALESCE(EXTRACT_VALUE(cs-uri-query, ‘id’), EXTRACT_VALUE(cs-uri-query, ‘SouborSablonyID’))) AS SouborID,
 COUNT(*) AS Total
 FROM ‘[LOGFILEPATH]’
 WHERE (cs-uri-stem = ‘/business/sablony/soubor-partner.aspx’) OR (cs-uri-stem = ‘/business/sablony/soubor.aspx’)
 GROUP BY Date, SouborID
 ORDER BY Total DESC
 [/code]

## Output to database

It is not only able to query the logs but you can use it to push the results to SQL database and many other supported data-sources (CSV, XML, …), e.g.

[code lang=”text” light=”true”]
 C:\Program Files (x86)\Log Parser 2.2>logparser “SELECT * INTO iisLogs FROM c:\temp\logs\*.log ” -i:iisw3c -o:SQL -server:localhost -database:MyLogs -username:sa -password:sa -createTable: ON
 [/code]

Note: If you want a plain import of log to DB (without any filtering, projection or aggregation) consider using *Import Flat File…* wizard from SQL Management Studio for better performance. If you want to use LogParser for feeding your DB, check the *transactionRowCount* option to batch uploaded rows into single transcation (e.g. `-transactionRowCount:-1`)

## Is there any GUI for LogParser?

LogParser itself has always been a command-line utility. As an alternative it has a COM API which allows you to use it from your application. This API has been used to produce several GUIs which make the use of LogParser much easier:

- [Microsoft LogParser Studio](https://blogs.technet.microsoft.com/exchange/2012/03/07/introducing-log-parser-studio/) ([download](https://gallery.technet.microsoft.com/Log-Parser-Studio-cd458765)) is a Microsoft product which brings not only the GUI itself but is shipped with many (181) pre-defined query templates for different log types.
   ![2017-11-28_2-46-39](https://i0.wp.com/knowledge-base.havit.eu/wp-content/uploads/2017/11/2017-11-28_2-46-39.png?resize=760%2C567&ssl=1)
- [Log Parser Lizard GUI](http://www.lizard-labs.com/log_parser_lizard.aspx) is another free tool (with a paid Pro edition) produced outside Microsoft which might be even more powerful. I haven’t tested it yet but it looks promising for those of you who need to play with the logs on daily basis.

## References

You might find following links useful when starting to play with LogParser:

- [How to analyse IIS logs using LogParser / LogParser Studio [IIS Field Readiness]](https://blogs.msdn.microsoft.com/friis/2014/02/06/how-to-analyse-iis-logs-using-logparser-logparser-studio/)
- [LogParser Functions [logparserplus.com]](http://logparserplus.com/functions/)
- [Analyze your IIS Log Files – Favorite Log Parser Queries [CarlosAg]](https://blogs.msdn.microsoft.com/carlosag/2010/03/25/analyze-your-iis-log-files-favorite-log-parser-queries/)
- [Log Parser Rocks! More than 50 Examples! [Mike Lichtenberg]](https://mlichtenberg.wordpress.com/2011/02/03/log-parser-rocks-more-than-50-examples/)
- [LogParser Forums [forums.iis.net]](https://forums.iis.net/default.aspx/51)
- [LogParser Performance Inserting into SQL Server](https://www.purplefrogsystems.com/blog/2013/08/logparser-performance-inserting-into-sql-server/)

