static void Main(string[] args) {
String machine = "."; // local machine
Console.WriteLine("-------------------------------------------------------------n");
if (args.Length == 1) {
if (args[0] == "application" || args[0] == "system" || args[0] == "security") {
String log = args[0];
EventLog aLog = new EventLog(log, machine);
EventLogEntry entry;
EventLogEntryCollection entries = aLog.Entries;
Stack < EventLogEntry > stack = new Stack < EventLogEntry > ();
for (int i = 0; i < entries.Count; i++) {
entry = entries[i];
stack.Push(entry);
}
entry = stack.Pop(); // only display the last record
Console.WriteLine("[Index]t" + entry.Index +
"n[EventID]t" + entry.InstanceId +
"n[TimeWritten]t" + entry.TimeWritten +
"n[MachineName]t" + entry.MachineName +
"n[Source]t" + entry.Source +
"n[UserName]t" + entry.UserName +
"n[Message]t" + entry.Message +
"n---------------------------------------------------n");
} else {
Console.WriteLine("Usage:glog.exe system(application,security)n");
}
} else {
Console.WriteLine("Usage:glog.exe system(application,security)n");
}
Console.WriteLine("end");
Console.ReadLine();
}