Coding Horror had a write up on the Microsoft LogParser. LogParser is an application that you can download and run via the command-line (there is also a COM DLL that you can use). You can write queries against the event log, the registry, CSV files, etc.
I downloaded it and gave it a try. Here is a walk through of a test that I did to query a CSV file(s).
The Test
I created a file called Test.csv that contains the following:
TimeStamp, MessageType, Message
2004-03-14 18:56:55, Warning, One
2004-03-14 14:02:23, Information, Two
2004-03-14 14:02:23, Information, Three
2004-03-14 12:00:00, Information, Four
2004-03-14 00:41:47, Warning, Five
2004-03-13 22:17:00, Information, Six
2004-03-13 22:06:48, Information, Seven
2004-03-13 22:06:48, Error, Eight
2004-03-13 12:00:00, Information, Nine
2004-03-12 22:30:47, Information, Ten
I saved the file to the C:\ and then from the command-line I did the following:
C:\Program Files\Log Parser 2.2>logparser "Select * from c:\test.csv"
The result of that was the following:
Filename RowNumber TimeStamp MessageType Message
----------- --------- ------------------- ----------- -------
c:\Test.csv 2 2004-03-14 18:56:55 Warning One
c:\Test.csv 3 2004-03-14 14:02:23 Information Two
c:\Test.csv 4 2004-03-14 14:02:23 Information Three
c:\Test.csv 5 2004-03-14 12:00:00 Information Four
c:\Test.csv 6 2004-03-14 00:41:47 Warning Five
c:\Test.csv 7 2004-03-13 22:17:00 Information Six
c:\Test.csv 8 2004-03-13 22:06:48 Information Seven
c:\Test.csv 9 2004-03-13 22:06:48 Error Eight
c:\Test.csv 10 2004-03-13 12:00:00 Information Nine
c:\Test.csv 11 2004-03-12 22:30:47 Information Ten
Statistics:
-----------
Elements processed: 10
Elements output: 10
Execution time: 0.00 seconds
I then copied the Test.csv file, creating "Copy of Test.csv", and ran the following:
C:\Program Files\Log Parser 2.2>logparser "Select Filename, TimeStamp, MessageType, Message from C:\*.csv where messageType ='Warning'"
The result of that was the following:
Filename TimeStamp MessageType Message
------------------- ------------------- ----------- -------
c:\Copy of Test.csv 2004-03-14 18:56:55 Warning One
c:\Copy of Test.csv 2004-03-14 00:41:47 Warning Five
c:\Test.csv 2004-03-14 18:56:55 Warning One
c:\Test.csv 2004-03-14 00:41:47 Warning Five
Statistics:
-----------
Elements processed: 20
Elements output: 4
Execution time: 0.02 seconds
Conclusion
The idea of being able to query a directory of files is cool.
There is a lot more to LogParser so download it an give it a try.
I also found an artical on using the LogParser DLL in a VBScript "All You Need is Log (Well, Log Parser)".
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment