开发者

need help parsing an IIS log in c#

My IIS log has a query parameter(cs-uri-query) that looks like below

"TraceId=8c0b8329-f125-4dec-90af-f508674284f5,PartnerI开发者_运维知识库d=Partner1\r\n,UserInput=Address1:+1234+block+of+XYZ+Street+Address2:+Santa+Fe+Springs+State:+California+ZipCode:+90000+Country:+United+States+"

I need to extract Address1,Address2,State,ZipCode and Country from the above line. also note that these fields need not always appear in the same order.

What is the best and quick way to parse this?I'am trying to do this using a c# command line tool.any other script based solution is also fine.


Take a look here: Simple log parsing using MS Log Parser 2.2, in C#.NET


LogParser is very good for this sort of thing. It's not necessary to write C# code however; you can access LogParser from the command line/in shell scripts. And to extract the data you want, the LogParser function EXTRACT_TOKEN would be of use. For example, to get the UserInput portion of that query string, you could say:

LogParser -i:IISW3C "SELECT EXTRACT_TOKEN(cs-uri-query, 3, '=') FROM ex10082012.log"

(Parsing it down into the Address1, Address2, etc. will require applying more nested "extracts" of course.)

For more info on how to use EXTRACT_TOKEN, look at the LogParser.chm file that comes with the install package, or run LogParser -h FUNCTIONS EXTRACT_TOKEN from the command line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜