Parse IIS log file - there is an alternative to LogParser

I need to parse the IIS log file. Is there an alternative to LogParser , a simple class for querying a log file?

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

Here is an example 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 
+6
source share
2 answers

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

and use it as follows:

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

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

+5
source

This is 2017, and LogParser is still closed. Moreover, all the tools provided by cloud solutions seem to force analysis of IIS logs in the past. But since I also deal with legacy applications, I wrote this simple parser using the .NET kernel.

 using System; using System.IO; using W3CParser.Extensions; using W3CParser.Instrumentation; using W3CParser.Parser; namespace W3CParser { class Program { static void Main(string[] args) { var reader = new W3CReader(File.OpenText(args.Length > 0 ? args[0] : "Data/foobar.log")); using (new ConsoleAutoStopWatch()) { foreach (var @event in reader.Read()) { Console.WriteLine("{0} ({1}):{2}/{3} {4} (bytes sent)", @event.Status.ToString().Red().Bold(), @event.ToLocalTime(), @event.UriStem.Green(), @event.UriQuery, @event.BytesSent); } } } } } 

Source code: https://github.com/alexnolasco/32120528

+5
source

All Articles