void WatcherEventRecordWritten(object sender, EventRecordWrittenEventArgs e) { // This method is being invoked every time that a entry was written to the event log. try { using (var stream = new MemoryStream()) { // Serialize EventLog's entry as Xml var writer = new StreamWriter(stream, Encoding.ASCII); var xml = e.EventRecord.ToXml(); writer.Write(xml); stream.Seek(0, SeekOrigin.Begin); // Publish a new message var urlToMessage = topic.PostMessage(stream, "application/xml"); // Prints new message's url Utils.WriteOnScrollableFrame(urlToMessage); } } catch (Exception ex) { // Prints any exception Console.WriteLine(ex.ToString()); } }
private void IssueCallback(EventRecordWrittenEventArgs eventArgs) { if (EventRecordWritten != null) { EventRecordWritten(this, eventArgs); } }
public override void NETErrorEventRecordWritten(object sender, System.Diagnostics.Eventing.Reader.EventRecordWrittenEventArgs e) { EventRecord r = e.EventRecord; // parse the data from the log's properties List <string> data = new List <string>(); foreach (EventProperty prop in r.Properties) { data.AddRange(prop.Value.ToString().Split('\n')); } // verify that it is related to the users app string appName = Path.GetFileNameWithoutExtension(Dte.Solution.FullName); if (data.Contains(appName + ".exe") && r.ProviderName == "Application Error") { // the user's app crashed while they ran it outside of debug mode. int code = int.Parse(data[6], System.Globalization.NumberStyles.HexNumber); // TODO: find name/type of exception from code EnvDTE.dbgExceptionAction action = dbgExceptionAction.dbgExceptionActionBreak; HandleException("Unknown Exception Type", "Unhandled exception", code, "The program encountered an unhandled run-time exception.", ref action); } }
private void OnEventWritten(object sender, EventRecordWrittenEventArgs e) { // Event has five properties: // [0] Counter name // [1] Counter value // [2] Operator // [3] Counter threshold // [4] Message string operatorString = (string)e.EventRecord.Properties[2].Value; switch (operatorString[0]) { case '<': this.OnThresholdReached(true); break; case '>': this.OnThresholdReached(false); break; } }
private void HandleEventsRequestCompletion() { if (this.asyncException != null) { EventRecordWrittenEventArgs eventArgs = new EventRecordWrittenEventArgs(this.asyncException); this.IssueCallback(eventArgs); } for (int i = 0; i < this.numEventsInBuffer; i++) { if (!this.isSubscribing) { return; } EventLogRecord record = new EventLogRecord(new EventLogHandle(this.eventsBuffer[i], true), this.eventQuery.Session, this.cachedMetadataInformation); EventRecordWrittenEventArgs args2 = new EventRecordWrittenEventArgs(record); this.eventsBuffer[i] = IntPtr.Zero; this.IssueCallback(args2); } }
private void HandleEventsRequestCompletion() { if (this.asyncException != null) { EventRecordWrittenEventArgs args = new EventRecordWrittenEventArgs(this.asyncException.Data["RealException"] as Exception); IssueCallback(args); } for (int i = 0; i < this.numEventsInBuffer; i++) { if (!this.isSubscribing) { break; } EventLogRecord record = new EventLogRecord(new EventLogHandle(this.eventsBuffer[i], true), this.eventQuery.Session, this.cachedMetadataInformation); EventRecordWrittenEventArgs args = new EventRecordWrittenEventArgs(record); this.eventsBuffer[i] = IntPtr.Zero; // user is responsible for calling Dispose(). IssueCallback(args); } }
// // Subscription callback displaying the delivered event // or an exception that occurred while retrieving the event. // private static void DisplayEventCallback(object value, EventRecordWrittenEventArgs callbackArg) { // Make sure there was no error reading the event. if (callbackArg.EventRecord != null) { Console.WriteLine("Received an event from the subscription:\n{0}\nFull event content in Xml:\n{1}\n\n", callbackArg.EventRecord.FormatDescription(), callbackArg.EventRecord.ToXml()); } else { Console.WriteLine("**Subscription encountered an error: \n{0}", callbackArg.EventException.ToString()); } }
private void EventRecordWritten(object sender, EventRecordWrittenEventArgs e) { try { EventRecord rec = e.EventRecord; string xml = rec.ToXml(); ProcessXml(xml); } catch (Exception ex) { Log.Write(LogLevel.Error, ex.ToString()); } }
/// <summary> /// Callback method that gets executed when an event is /// reported to the subscription. /// </summary> private void EventRead(object obj, EventRecordWrittenEventArgs arg) { EventLogWatcher watcher = obj as EventLogWatcher; EventLogRecord evtlog = (EventLogRecord)arg.EventRecord; EventLogException evtex = (EventLogException)arg.EventException; if (evtlog == null) { if (evtex == null) { Log.Error("No event log info!?"); } else { Log.Error("No event log info, received exception: " + arg.EventException.Message); } return; } long recordId = 0; DateTime created = DateTime.Now; string hostname = null; IList<object> evtdata = null; try { // without this synchronization we sometimes get corrupted evtlog // data with invalid handle (EventLogException) lock (eventLock) { recordId = evtlog.RecordId.GetValueOrDefault(0); created = evtlog.TimeCreated.Value; hostname = evtlog.MachineName; evtdata = evtlog.GetPropertyValues(evtsel); } } catch (EventLogException ex) { Log.Error("Unable to access log info: " + ex.Message); return; } catch (Exception ex) { Log.Error("Unable to access log info: " + ex.Message); return; } if (Log.Level == EventLogEntryType.Information) { // debug info Log.Info("EventLog[" + recordId + "@" + Name + "]: new log event received"); // more debug info for (int i = 0; i < evtdata.Count; i++) { if (evtdata[i] != null) { if (evtdata[i].GetType().IsArray) { foreach (string item in (object[])evtdata[i]) { Log.Info("EventLog[" + recordId + "@" + Name + "][" + i + "](" + evtdata[i].GetType() + "):" + item.ToString()); } } else { Log.Info("EventLog[" + recordId + "@" + Name + "][" + i + "](" + evtdata[i].GetType() + "):" + evtdata[i].ToString()); } } else { Log.Info("EventLog[" + recordId + "@" + Name + "][" + i + "]: NULL!!!"); } } } string strAddress = GetLogRecordData(evtdata, evtregex, "address"); string strPort = GetLogRecordData(evtdata, evtregex, "port"); string strUsername = GetLogRecordData(evtdata, evtregex, "username"); string strDomain = GetLogRecordData(evtdata, evtregex, "domain"); if (strAddress == null) { Log.Info("EventLog[" + recordId + "@" + Name + "] unable to get address"); return; } IPAddress address = null; try { address = IPAddress.Parse(strAddress.Trim()).MapToIPv6(); } catch (FormatException ex) { Log.Info("EventLog[" + recordId + "@" + Name + "] invalid address" + strAddress.Trim() + " (" + ex.Message + ")"); return; } int port = -1; try { port = int.Parse(strPort); } catch (Exception) { // intentionally skip parser exeption for optional parameter } EventEntry evt = new EventEntry(created, hostname, address, port, strUsername, strDomain, Login, this, arg); Log.Info("EventLog[" + recordId + "->" + evt.Id + "@" + Name + "] queued message " + strUsername + "@" + address + ":" + port + " from " + hostname + " status " + Login); equeue.Produce(evt, Processor); }
private void EventRecordWritten(object sender, EventRecordWrittenEventArgs e) { EventRecord rec = e.EventRecord; string xml = rec.ToXml(); ProcessXml(xml); }
public void EventLogEventRead(object obj, EventRecordWrittenEventArgs arg) { if (arg.EventRecord != null) { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(arg.EventRecord.ToXml()); var @event = new Event { EventId = arg.EventRecord.Id, EventRecordId = arg.EventRecord.RecordId, LogName = arg.EventRecord.LogName, Message = string.Join(Environment.NewLine, arg.EventRecord.Properties.Select(property => property.Value.ToString())), Source = arg.EventRecord.ProviderName, Date = arg.EventRecord.TimeCreated.Value.ToUniversalTime().ToString(_time.Format), Level = arg.EventRecord.LevelDisplayName, MachineName = Environment.MachineName }; _connection.Log(@event); } }
private void IssueCallback(EventRecordWrittenEventArgs eventArgs) { EventRecordWritten?.Invoke(this, eventArgs); }
private void HandleEventsRequestCompletion() { if (this.asyncException != null) { EventRecordWrittenEventArgs eventArgs = new EventRecordWrittenEventArgs(this.asyncException); this.IssueCallback(eventArgs); } for (int i = 0; i < this.numEventsInBuffer; i++) { if (!this.isSubscribing) { return; } EventLogRecord record = new EventLogRecord(new EventLogHandle(this.eventsBuffer[i], true), this.eventQuery.Session, this.cachedMetadataInformation); EventRecordWrittenEventArgs args2 = new EventRecordWrittenEventArgs(record); this.eventsBuffer[i] = IntPtr.Zero; this.IssueCallback(args2); } }
private void EventRecordWritten(object sender, EventRecordWrittenEventArgs e) { if (OnNewLogEntry != null) { EventRecord rec = e.EventRecord; string xml = RemoveAllNamespaces(XElement.Parse(rec.ToXml())).ToString(); using (StringReader stream = new StringReader(xml)) { XPathDocument xpath = new XPathDocument(stream); XPathNavigator navigator = xpath.CreateNavigator(); OnNewLogEntry(rec.Id, new NewLogEntryArguments() { xml = xml, navigator = navigator }); } } }
private void IssueCallback(EventRecordWrittenEventArgs eventArgs) { if (EventRecordWritten != null) { EventRecordWritten(this, eventArgs); } }
private void HandleEventsRequestCompletion() { if (this.asyncException != null) { EventRecordWrittenEventArgs args = new EventRecordWrittenEventArgs(this.asyncException.Data["RealException"] as Exception); IssueCallback(args); } for (int i = 0; i < this. numEventsInBuffer; i++) { if (!this.isSubscribing) break; EventLogRecord record = new EventLogRecord(new EventLogHandle(this.eventsBuffer[i], true), this.eventQuery.Session, this.cachedMetadataInformation); EventRecordWrittenEventArgs args = new EventRecordWrittenEventArgs(record); this.eventsBuffer[i] = IntPtr.Zero; // user is responsible for calling Dispose(). IssueCallback(args); } }
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); } }