/// <summary> /// Loads the eventlog entry collection /// </summary> private void LoadEventLogEntryCollection() { //This is only called when the log is changed and when the class is instantiated so it's pretty safe //to re-init the collection this.eventLogEntryCollection = new EventLogEntryCollection(); string[] attributes = new string[] { "machineName", "userName", "timeGenerated", "source", "message", "eventLogEntryType", "eventID", "category", "rawData", "id", "timeWritten", "index" }; //Get all the eventLog nodes foreach (XmlNode node in this.nodeLog.ChildNodes) { string machineName = node.Attributes.GetNamedItem(attributes[0]).Value; string userName = node.Attributes.GetNamedItem(attributes[1]).Value; DateTime timeGenerated = DateTime.Parse(node.Attributes.GetNamedItem(attributes[2]).Value); string source = node.Attributes.GetNamedItem(attributes[3]).Value; string message = node.Attributes.GetNamedItem(attributes[4]).Value; EventLogEntryType type = (EventLogEntryType)Int32.Parse(node.Attributes.GetNamedItem(attributes[5]).Value); int eventID = Int32.Parse(node.Attributes.GetNamedItem(attributes[6]).Value); short category = Int16.Parse(node.Attributes.GetNamedItem(attributes[7]).Value); string srawData = node.Attributes.GetNamedItem(attributes[8]).Value; byte[] rawData = new byte[0]; if (srawData.Length > 0) { rawData = Convert.FromBase64String(srawData); } string id = node.Attributes.GetNamedItem(attributes[9]).Value; DateTime timeWritten = DateTime.Parse(node.Attributes.GetNamedItem(attributes[10]).Value); int index = Int32.Parse(node.Attributes.GetNamedItem(attributes[11]).Value); //Add to the collection EventLogEntry eventLogEntry = new EventLogEntry(category, rawData, type, eventID, index, machineName, message, source, timeGenerated, timeWritten, userName, id); this.eventLogEntryCollection.Add(eventLogEntry); } }
public void Close() { this.SaveLogFile(); this.nodeLog = null; this.log = ""; this.source = ""; this.logDisplayName = ""; this.eventLogEntryCollection = new EventLogEntryCollection(); }
public void Clear() { //Clear all the log items from the xml int y = this.nodeLog.ChildNodes.Count; for (int x = 0; x < y; x++) { this.nodeLog.RemoveChild(this.nodeLog.ChildNodes[0]); } //Save the xml file this.SaveLogFile(); //Re-init the eventLogCollection this.eventLogEntryCollection = new EventLogEntryCollection(); }