News

Useful Tool: Microsoft Log Parser

Every once in a while, I run across a little-known but very useful tool. Microsoft Log Parser falls squarely into this category. Originally developed to extract information from IIS logs, it has expanded its capabilities to become an all-purpose tool for applying SQL queries to text files (and other types of files, for that matter).

For example, you might be faced with a pile of IIS log files and the question: which file types are holding things up here? One way to answer this is to determine the average processing time for each extension, and the easy way to handle that is to use Log Parser from the command line:


logparser "SELECT EXTRACT_TOKEN (cs-uri-stem, -1, '.' ) AS Extension,
AVG(time-taken) FROM ex*.log GROUP BY Extension"

That's just a small sample of what Log Parser can do. It implements a reasonably complete SQL dialect, so you can filter or sort or aggregate results.

It also understands the formats of many different types of input file, including IIS logs, Windows event logs, CSV files, standard W3C log files, and line-oriented text files. You also have a choice of outputs, including straight to the command prompt, to a grid control, to a SQL table, or to an XML file.

Any time you're faced with the necessity to wade through a lot of textual data to find some bits, or to analyze patterns, it's worth thinking of this tool. You can download a copy for free as part of the IIS 6.0 Resource Kit. If you'd like to find out more, visit my own unofficial support site for the product. And I'd love to hear about any innovative uses that you come up for being able to parse log files.

About the Author

Mike Gunderloy has been developing software for a quarter-century now, and writing about it for nearly as long. He walked away from a .NET development career in 2006 and has been a happy Rails user ever since. Mike blogs at A Fresh Cup.