If you need to parse log files, before you decide to write your own parser, try using the free Log Parser from Microsoft:
Log parser is a powerful, versatile tool that provides universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows® operating system such as the Event Log, the Registry, the file system, and Active Directory®. You tell Log Parser what information you need and how you want it processed. The results of your query can be custom-formatted in text based output, or they can be persisted to more specialty targets like SQL, SYSLOG, or a chart.
This post shows a nice example of SMTP Log Parsing, with the process automated via PowerShell.
The TechNet script centre contains several Examples of using LogParser.