This post was recovered from archive.org. It was origionally posted on Wednesday, October 25, 2004
I recently had the desire to put my IIS logs in a SQL database but I didn’t want to lose the cached hits (since if you use ODBC logging in IIS 6 it won’t log anything that it found in its cache) so I was planning on writing an application to do this until I found the IIS 6 Log Parser in the IIS 6 Resource Kit. This tool is extremely nice. You can just set IIS to log to W3C Extended Log File Format (IISW3C). Then you can use the LogParser.exe command line interface to parse the log file and insert it directly into a SQL database. To do this is as easy as this:
logparser “select * from mylogfile.log to mydatabase.dbo.mylogfiletable“ -i:IISW3C -o:SQL -driver:“SQL Server“ -server:mysqlserver -username:bob -password:moo
And that’s it. You now have your entire log file parsed into your SQL database. You can also use this to dump to other formats including XML. And as you could have guessed you can get much more creative with your select query…
Now that you're thinking “well that’s kind of cool...” (I hope assuming you’ve read this far) this tool also has a COM interface. This means you can easily write applications that use your log files as a data source in any language that can support COM. Seeing how I’m a C# guy I wrote a little test application for this. About 15 min and roughly 30 lines of code later I had a working model that executed a query on a IISW3C format log file and returned the results in a DataTable that I then bound to a DataGrid. From here you should be able to generate all sorts of interesting reports and stats from your web site logs.
All in all I’m very impressed with this little utility and I though some of you may be interested in my findings…
You can download my source code for my C# demo application here (Still trying to find the demos, sorry)). You'll also need the IIS 6 Resource Kit to do anything I talked about in this post. You can download that here.