Com through. NET Framework
InterOP(COM Interactive Operation) features, can be easily applied in. netProgramUsing Log parser,. NET Framework com
InterOPIs implemented through runtime callable wrappers (RCW) for com operations, RCW is a class in. net.
Compiling environment: vs2005 C #
First, add reference: logparser. DLL to your new project, and then it appears in the reference bar of your solution: msutil. You can find various types of interfaces in the library in the Object Browser. Next, reference the type you want to call at the beginning of your CS file, for example, using logquery = msutil. logqueryclassclass; using logrecordset = msutil. ilogrecordset; using logrecord = msutil. ilogrecord; using w3cloginputformat = msutil. comw3cinputcontextclassclass; using csvlogoutputformat = msutil. comcsvoutputcontextclassclass;
For example, use Log parser and C # to create a website access statistical analysis system. Use C # To call log parser and use Log parser to analyze IIS log files. Here, the log file is in W3C format.
Create a. CS file and introduce:
Using logquery = InterOP. msutil. logqueryclassclass;
Using iisinputformat = InterOP. msutil. comiisw3cinputcontextclassclass;
Using logrecordset = InterOP. msutil. ilogrecordset;
Class keyCodeAs follows:
Logquery ologquery = new logquery ();
Iisinputformat oiisinputformat = new iisinputformat ();
String query = @ "select count (distinct C-IP) as hits
From 'C: \ windows \ system32 \ logfiles \ w3svc1 \ ex07081_log'
Where CS-Uri-stem like '%. asp'
And SC-status = 200 ";
Logrecordset orecordset = ologquery. Execute (query, oiisinputformat );
If (! Orecordset. atend ())
{
Hits = (INT) orecordset. getrecord (). getvalue ("hits ");
}
Orecordset. Close ();
It can be seen that it is not much different from using the database. In the query statement, C-IP, CS-Uri-stem, SC-status, and so on are all log file fields, you can directly open the log file to find the content.
Through the combination of C # And logparser, You can maximize the functions of logparsr. So that it is not limited to command line input...