Windowsフォームのpublic static List<EventLogEntry> _LogEntries { get; private set; }
にdataGridView
というイベントログのリストを取得する必要があります。イベントログのリストをdataGridViewに取得しようとしています。 ReadEventLog()メソッドでエラーが発生する
最新号:毎回私は型「System.ArgumentExceptionの」の未処理の例外がライン
EventLog eventLog = new EventLog(EvlLocation);
でSystem.dllので発生し、それは例外を破るReadEventLog()
メソッドを呼び出します最初に私はファイルを開きます
// Open the log file
private void OpenFile()
{
string evlLocation = "";
// Show file open dialog
if (openFile.ShowDialog() == DialogResult.OK)
{
// Create a dataset for binding the data to the grid.
ds = new DataSet("EventLog Entries");
ds.Tables.Add("Events");
ds.Tables["Events"].Columns.Add("ComputerName");
ds.Tables["Events"].Columns.Add("EventId");
ds.Tables["Events"].Columns.Add("EventType");
ds.Tables["Events"].Columns.Add("SourceName");
ds.Tables["Events"].Columns.Add("Message");
// Start the processing as a background process
evlLocation = openFile.FileName;
parser.setLogLocation(openFile.FileName);
worker.RunWorkerAsync(openFile.FileName);
}
}
//次に、以下のmetho dが呼び出されます。 public EventLog(string logName)
- - 呼び出されたときにReadEventLog()
// Bind the dataset to the grid.
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
parser.ReadEventLog();
bs = new BindingSource(ds, "Events");
Foo foo1 = new Foo("TEST PC");
ComputerName.Add(foo1);
bs.DataSource = parser._LogEntries;
//Bind fooList to the dataGridView
dataGridView1.DataSource = bs;
this.Invoke(pbHandler, new object[] { 100, 100 });
}
は、その後、それはEventLog eventLog = new EventLog(EvlLocation);
ReadEventLog()
方法EventLog Constructor (String)のためのMSDNのドキュメントで
public static void ReadEventLog()
{
// Line in question below
EventLog eventLog = new EventLog(EvlLocation);
EventLogEntryCollection eventLogEntries = eventLog.Entries;
int eventLogEntryCount = eventLogEntries.Count;
for (int i = 0; i < eventLogEntries.Count; i++)
{
EventLogEntry entry = eventLog.Entries[i];
//Do Some processing on the entry
}
_LogEntries = eventLogEntries.Cast<EventLogEntry>().ToList();
}