Parse IIS log file - is there an alternative to LogParser

Anas picture Anas · Aug 20, 2015 · Viewed 13.9k times · Source

I need to parse an IIS log file. Is there any alternative to LogParser, a simple class to query a log file ?

I only need to know how many request I receive between 2 dates.

Here is an example of iis log file :

#Software: Microsoft Internet Information Services 7.5
#Version: 1.0
#Date: 2014-08-26 12:20:57
#Fields: date time s-sitename s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2014-08-26 12:20:57 W3SVC1 QXXXSXXXX 172.25.161.53 POST /XXXX/XXX/XXXX/XXXXX/1.0/XXXX/XXXXXXXX/xxxxxx.svc - 443 - 999.99.999.999 HTTP/1.1 - - - xxxx.xxxx.xxx.xxx.xxxx.xxxx.xxx.com 200 0 0 4302 5562 1560

Answer

Anas picture Anas · Aug 21, 2015

You can use Tx (LINQ to Logs and Traces) , you can install it via nuget

and use it like this:

var iisLog = W3CEnumerable.FromFile(pathToLog);
int nbOfLogsForLastHour = iisLog.Where(x => x.dateTime > DateTime.Now.AddHours(-1)).Count();

If the log file is used by another process, you can use W3CEnumerable.FromStream