//我创建了一个应用程序,它从事件查看器获取事件日志并存储在数据库中,现在我想在记录特定事件时触发该代码 // thi Code获取事件日志并将其存储在数据库中...
try
{
EventLog el = new EventLog();
el.Log = "Security";
el.MachineName = ".";
Query q = new Query();
foreach (EventLogEntry en in el.Entries )
{
if (if en.EventID==4688)
{
q.Insert("insert into EventLog (MachineName,Username,InstanceID,EventMsg,TimeGenerated) values ('" + en.MachineName + "', '" + en.UserName + "','" + en.InstanceId + "','" + en.Message + "','" + en.TimeGenerated + "')", q.Con());
}
}
}
catch (Exception x)
{
MessageBox.Show(x.Message );
}