erhalten Ich muss diese Liste der Ereignisprotokolle public static List<EventLogEntry> _LogEntries { get; private set; }
in dataGridView
in Windows Forms abrufen.Der Versuch, eine Liste von Ereignisprotokollen in ein dataGridView zu bekommen | Fehler bei der ReadEventLog() -Methode
Aktuelle Ausgabe: Jedesmal, nenne ich die Methode
ReadEventLog()
es mit Ausnahme bricht Eine nicht behandelte Ausnahme des Typs 'System.ArgumentException' in System.dll an der Linie aufgetretenEventLog eventLog = new EventLog(EvlLocation);
Zuerst öffne ich die Datei
// 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);
}
}
// Dann die folgenden Methoden d heißt.
// 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 });
}
Dann, wenn ReadEventLog()
genannt wird, bricht es an der Linie EventLog eventLog = new EventLog(EvlLocation);
ReadEventLog()
Methode unter
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();
}