public override void WriteLine(string message) { ProbeHistory probeHistory; if (!_probeStates.TryGetValue("(Console)", out probeHistory)) { ProbeInfo probeInfo = new ProbeInfo(); probeInfo.Name = "(Console)"; if (_probes.Probes == null) { _probes.Probes = new List <ProbeInfo>(); } _probes.Probes.Add(probeInfo); probeHistory = new ProbeHistory(); probeHistory.Name = "(Console)"; probeHistory.History = new List <ProbeState>(); _probeStates.Add(probeHistory.Name, probeHistory); } ProbeState probeState = new ProbeState(); probeState.Timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); probeState.Message = message; AddProbeState(probeState, ref probeHistory); }
public void UpdateState(ProbeState state) { EventId = state.EventId; Timestamp = state.Timestamp; Status = state.Status; Value = state.Value; Message = state.Message; }
void AddProbeState(ProbeState probeState, ref ProbeHistory probeHistory) { probeHistory.History.Insert(0, probeState); probeHistory.History.RemoveAll(delegate(ProbeState state) { return(DateTime.Now.Subtract(DateTime.Parse(state.Timestamp)) > TimeSpan.FromDays(1)); }); string name = probeHistory.Name; ProbeInfo probeInfo = _probes.Probes.Find(delegate(ProbeInfo probe) { return(probe.Name == name); }); if (probeInfo != null) { probeInfo.UpdateState(probeState); } }
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id) { ProbeHistory probeHistory; if (_probeStates.TryGetValue(source, out probeHistory)) { ProbeState probeState = new ProbeState(); probeState.EventId = id; probeState.Timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); probeState.Status = eventType.ToString(); AddProbeState(probeState, ref probeHistory); } }
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) { ProbeHistory probeHistory; if (_probeStates.TryGetValue(source, out probeHistory)) { string value = ""; try { using (System.IO.StringReader reader = new System.IO.StringReader(message)) { System.Xml.XPath.XPathDocument xmlDoc = new System.Xml.XPath.XPathDocument(reader); System.Xml.XPath.XPathNavigator xmlNav = xmlDoc.CreateNavigator(); if (eventType != TraceEventType.Critical) { value = xmlNav.SelectSingleNode("//Value").InnerXml; } } } catch (Exception) { } string eventMessage = message; try { using (System.IO.StringReader reader = new System.IO.StringReader(message)) { System.Xml.XPath.XPathDocument xmlDoc = new System.Xml.XPath.XPathDocument(reader); System.Xml.XPath.XPathNavigator xmlNav = xmlDoc.CreateNavigator(); eventMessage = xmlNav.SelectSingleNode("//Message").InnerXml; } } catch (Exception) { } ProbeState probeState = new ProbeState(); probeState.EventId = id; probeState.Message = eventMessage; probeState.Value = value; probeState.Timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); probeState.Status = eventType.ToString(); AddProbeState(probeState, ref probeHistory); } }
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data) { ProbeHistory probeHistory; if (_probeStates.TryGetValue(source, out probeHistory)) { ProbeState probeState = new ProbeState(); probeState.EventId = id; if (data != null && data.Length > 0) { probeState.Message = data[0].ToString(); } probeState.Timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); probeState.Status = eventType.ToString(); AddProbeState(probeState, ref probeHistory); } }
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args) { ProbeHistory probeHistory; if (_probeStates.TryGetValue(source, out probeHistory)) { ProbeState probeState = new ProbeState(); probeState.EventId = id; if (format != null && args != null) { probeState.Message = String.Format(format, args); } else { probeState.Message = format; } probeState.Timestamp = DateTime.Now.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); probeState.Status = eventType.ToString(); AddProbeState(probeState, ref probeHistory); } }