Here's my code that works. I actually dumped log files from System, Application and Security logs into the database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// Log Parser 2.2
using MSUtil;
namespace LogParser2 {
public partial class _Default :System.Web.UI.Page {
// constants
const string iCHECKPOINT_FILE_LOCATION = @"c:\checkpoint.lpc"; // iCheckpoint allows incremental parsing
protected void Page_Load(object sender, EventArgs e) {
GetSystemEventLogToSql();
}
private void GetSystemEventLogToSql() {
try {
// Instantiate the LogQuery object
LogQueryClassClass LogQuery = new LogQueryClassClass();
// Instantiate the Event Log Input Format object
COMEventLogInputContextClassClass EvtInputFormat = new COMEventLogInputContextClassClass();
// Set Input Parameters.
EvtInputFormat.direction = "BW";
// iCheckpoint parses input incrementally. Give it a location.
EvtInputFormat.iCheckpoint = @"c:\checkpoint.lpc";
// Instantiate the Event Log Output Format object
COMSQLOutputContextClassClass EvtOutputFormat = new COMSQLOutputContextClassClass();
// Set Output Parameters
EvtOutputFormat.driver = "SQL Server";
EvtOutputFormat.server = "ServerName";
EvtOutputFormat.database = "DatabaseName";
EvtOutputFormat.username = "UserName";
EvtOutputFormat.password = "Password";
// I created the tables and added an ID Column. It needs to be ignored during the insert.
EvtOutputFormat.ignoreIdCols = true;
// Create the query
// tblLogWebSystem is the name of the table I am inserting these records into in my DB
string Query = @"SELECT * FROM TO tblLogWebSystem";
// Execute the query into SQL
LogQuery.ExecuteBatch(Query, EvtInputFormat, EvtOutputFormat);
Response.Write("Done");
}
catch(System.Runtime.InteropServices.COMException exc) {
Response.Write("Unexpected error: " + exc.Message);
}
}
}
}