Weird Error of Log Parser

Log Parser is a great Microsoft tool for processing text-based data. Its scriptable COM components can be easily consumed by .NET applications.

Recently I ran into an interesting error when using the COM components with C#. The data input for the parser is a TSV ((tab-separated values) formatted text log file. Here is code:

LogQueryClassClass logQuery = new LogQueryClassClass();
COMTSVInputContextClassClass inputContext = new COMTSVInputContextClassClass();
inputContext.iCheckpoint = “MyCheckpoint.lpc”;
ILogRecordset recordSet = logQuery.Execute(“SELECT * FROM test.log”, inputContext);

I got all NULL values in the result recordsĀ or the following exception:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x80094004): Error parsing query: Header for file “test.log” contains an empty field name declaration [Unknown Error]

The weird thing is if I commented out the line which assigns iCheckpoint for incremental parsing, the code would work. Eventually I found out that I needed to specify the CodePage of the inputContext since the text input was encoded in Unicode. So the solution is to add the following line:

inputContext.CodePage = -1; // -1 is Unicode, default (0) is the system codepage

Leave a Reply

Your email address will not be published. Required fields are marked *