Find 404 errors using Log Parser

Note: This article was written using Log Parser 2.2. Therefore, while it may work for a different version, it may not.

The following code will generate a listing of calls that generated a 404 error.

logparser "SELECT cs-uri-stem, cs-uri-query, date, sc-status, cs(Referer) INTO 404report.txt FROM ex.log WHERE sc-status = 404 ORDER BY date, cs-uri-stem, cs-uri-query"

This assumes that you've currently got a command line open in the folder containing your IIS logs, and that you are logging the above information, as well as that logparser is setup in your PATH line.

A file called '404report.txt' will be generated in the folder containing your log files, which will list the above five fields. It's possible to generate a count instead, but I have no done so above.

Here's one that generates a count with pages and referers listed, of 404 pages.

logparser "SELECT cs-uri-stem AS page, cs(Referer) AS referer, count() AS hits INTO 404report.txt FROM ex*.log WHERE sc-status = 404 GROUP BY page, referer ORDER BY page"

All-in-all, I'm pretty impressed by this tool, once you have time to actually work with it. 

Update, 2007.09.09

Updated both codes to export to 404report.txt, instead of just report.txt.