public void EventLogEventRead(object obj, EventRecordWrittenEventArgs arg) { try { if (arg.EventRecord != null) { // check on keywords in the General Description and send message to the Nagios server if (supressedIDs != null && supressedIDs.Contains(arg.EventRecord.Id)) { return; } if (EventRaised != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // need to fix MS bug EventLogRecord r = (EventLogRecord)arg.EventRecord; string msg = r.FormatDescription(); string mPath = ""; if (string.IsNullOrWhiteSpace(msg)) { using (var eln = new System.Diagnostics.EventLog(r.LogName, r.MachineName)) { System.Diagnostics.EventLogEntryCollection eCollection = eln.Entries; int cnt = eCollection.Count; for (int i = cnt - 1; i >= Math.Max(0, cnt - 200); i--) { var xe = eCollection[i]; if (xe.Index == r.RecordId) { msg = xe.Message; mPath = " s"; break; } } } } if (_rxFilter != null && string.IsNullOrWhiteSpace(msg) == false && !_rxFilter.IsMatch(msg)) { return; } string fMsg = string.Format("{0}, EventID = {1}{2}{3}", arg.EventRecord.TimeCreated.HasValue ? arg.EventRecord.TimeCreated : DateTime.Now, r.Id & 0xFFFF, System.Environment.NewLine, msg); EventRaised.Invoke(this, new EventWatcherArgs(this.EventDescription.NagiosServiceName, this.EventDescription.MessageLevel, fMsg)); } } } catch (Exception ex) { Nagios.Net.Client.Log.WriteLog(ex.Message + "\n" + ex.StackTrace, true); } }
private string oldIndexDirPath() { EventLogFile log = new EventLogFile(); System.Diagnostics.EventLogEntryCollection ELEC = log.ReadAllEntry(); for (int i = ELEC.Count - 1; i >= 0; i--) { if ((ELEC[i].Message).StartsWith("created@")) { return((ELEC[i].Message).Replace("created@", string.Empty)); } } return(string.Empty); }