public void TraceXmlLogEntryWithPayload() { XmlLogEntry xmlLogEntry = CommonUtil.CreateXmlLogEntry(); source.TraceData(TraceEventType.Error, 1, xmlLogEntry); AssertTempFileNameHasSomeContent(); }
public void CanDeserializeLogEntryXmlUsingBinaryFormatter() { XmlLogEntry entry = CommonUtil.CreateXmlLogEntry(); string serializedLogEntryXmlText = new BinaryLogFormatter().Format(entry); XmlLogEntry desiaralizedLogEntryXml = (XmlLogEntry)BinaryLogFormatter.Deserialize(serializedLogEntryXmlText); Assert.IsNotNull(desiaralizedLogEntryXml); CommonUtil.AssertXmlLogEntries(entry, desiaralizedLogEntryXml); }
public void Log(LogLevel level, string message) { XmlLogEntry entry = new XmlLogEntry(); entry.Level = level; entry.Message = message; this.log.LogEntries.Add(entry); }
public void FormatXmlLogEntry() { XmlLogEntry logEntry = CommonUtil.CreateXmlLogEntry(); string xml = xmlLogFormatter.Format(logEntry); Assert.IsFalse(string.IsNullOrEmpty(xml)); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(xml); Assert.IsNotNull(xmlDocument.FirstChild); }
public static XmlLogEntry CreateXmlLogEntry(string xml, string[] categories) { XmlLogEntry entry = new XmlLogEntry(); FillLogEntry(entry); entry.Categories = new List <string>(categories); entry.Xml = new XPathDocument(new StringReader(xml)).CreateNavigator(); return(entry); }
public void ProxyXPathNavigatorData() { XPathNavigator navigator = new XPathDocument(new StringReader(CommonUtil.Xml)).CreateNavigator(); proxy.TraceData(new TraceEventCache(), CommonUtil.ServiceModelCategory, TraceEventType.Error, 1, navigator); Assert.IsTrue(MockTraceListener.LastEntry is XmlLogEntry); XmlLogEntry lastEntry = MockTraceListener.LastEntry as XmlLogEntry; Assert.AreEqual(lastEntry.Xml, navigator); }
public void TracingXPathNavigatorWithoutConfiguredCategoriesQueryCreatesLogEntryWithoutCategories() { XPathNavigator navigator = new XPathDocument(new StringReader(xmlPayloadString)).CreateNavigator(); proxy.TraceData(new TraceEventCache(), CommonUtil.ServiceModelCategory, TraceEventType.Error, 1, navigator); Assert.IsTrue(MockTraceListener.LastEntry is XmlLogEntry); XmlLogEntry lastEntry = MockTraceListener.LastEntry as XmlLogEntry; Assert.AreSame(lastEntry.Xml, navigator); Assert.AreEqual(1, lastEntry.Categories.Count); Assert.IsTrue(lastEntry.Categories.Contains(CommonUtil.ServiceModelCategory)); }
public void ProxyXmlLogEntryData() { XmlLogEntry entry = CommonUtil.CreateXmlLogEntry(); int eventId = 1; entry.EventId = eventId; entry.Categories.Add(CommonUtil.ServiceModelCategory); proxy.TraceData(new TraceEventCache(), CommonUtil.ServiceModelCategory, TraceEventType.Error, eventId, entry); Assert.IsTrue(MockTraceListener.LastEntry is XmlLogEntry); XmlLogEntry lastEntry = MockTraceListener.LastEntry as XmlLogEntry; Assert.IsNotNull(lastEntry); CommonUtil.AssertXmlLogEntries(lastEntry, entry); }
public void TracingXPathNavigatorWithConfiguredCategoriesQueryForExistingValueCreatesLogEntryWithExtraCategories() { XPathNavigator navigator = new XPathDocument(new StringReader(xmlPayloadString)).CreateNavigator(); proxy.Attributes.Add("categoriesXPathQueries", @"//mt:MessageLogTraceRecord/@Source"); proxy.Attributes.Add("namespaces", @"xmlns:mt='http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace'"); proxy.TraceData(new TraceEventCache(), CommonUtil.ServiceModelCategory, TraceEventType.Error, 1, navigator); Assert.IsTrue(MockTraceListener.LastEntry is XmlLogEntry); XmlLogEntry lastEntry = MockTraceListener.LastEntry as XmlLogEntry; Assert.AreSame(lastEntry.Xml, navigator); Assert.AreEqual(2, lastEntry.Categories.Count); Assert.IsTrue(lastEntry.Categories.Contains(CommonUtil.ServiceModelCategory)); Assert.IsTrue(lastEntry.Categories.Contains(@"TransportSend")); }
/// <summary> /// Writes trace information, a data object and event information through the Logging Block. /// </summary> /// <param name="eventCache">A <see cref="TraceEventCache"/> object that contains the current process ID, thread ID, and stack trace information.</param> /// <param name="source">An identification of the source of the trace request.</param> /// <param name="eventType">One of the <see cref="TraceEventType"/> values specifying the type of event that has caused the trace.</param> /// <param name="id">A numeric identifier for the event.</param> /// <param name="data">The trace data to emit.</param> public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { if ((Filter == null) || Filter.ShouldTrace(eventCache, source, eventType, id, null, null, data, null)) { Dictionary <string, object> properties = new Dictionary <string, object>(); properties.Add(TraceEventCacheKey, eventCache); LogEntry logEntry; if (data is XPathNavigator) { XPathNavigator xmlData = data as XPathNavigator; List <string> categories = new List <string>(); categories.Add(source); foreach (string xpathQuery in CategoriesXPathQueries) { XPathNodeIterator nodeIterator = xmlData.Select(xpathQuery, NamespaceManager); foreach (object value in nodeIterator) { categories.Add(((XPathNavigator)value).Value); } } XmlLogEntry xmlLogEntry = new XmlLogEntry(data, categories, int.MaxValue, id, eventType, null, properties); xmlLogEntry.Xml = xmlData; logEntry = xmlLogEntry; } else if (data is LogEntry) { logEntry = data as LogEntry; } else { logEntry = new LogEntry(data, string.IsNullOrEmpty(source) ? new string[0] : new string[] { source }, int.MaxValue, id, eventType, null, properties); } Logger.Write(logEntry); } }
static void EntLibTest() { while (true) { Console.WriteLine("Press any key or 'q' to quit..."); ConsoleKeyInfo k = Console.ReadKey(); if (k.KeyChar == 'q') { break; } if (Logger.IsLoggingEnabled()) { Logger.Write("[Enter]Enter Method"); Logger.Write("Message1"); Logger.Write("Information", "General", 0, 0, TraceEventType.Information); Logger.Write("Critical", "General", 0, 0, TraceEventType.Critical); Logger.Write("Error", "General", 0, 0, TraceEventType.Error); Logger.Write("Warning", "General", 0, 0, TraceEventType.Warning); // Log a message with XML content XmlLogEntry xmlEntry = new XmlLogEntry(); xmlEntry.Categories.Add("General"); xmlEntry.Severity = TraceEventType.Information; xmlEntry.Message = "Sample XML"; xmlEntry.Xml = GetSampleXmlDocumet().CreateNavigator(); Logger.Write(xmlEntry); // Log a message with extended property extensions LogEntry lEntry = new LogEntry(); lEntry.Categories.Add("General"); lEntry.Severity = TraceEventType.Information; lEntry.Message = "message with extended properties."; lEntry.ExtendedProperties["ClientId"] = 1234; lEntry.ExtendedProperties["CompanyId"] = 7895; lEntry.ExtendedProperties["State"] = "CA"; Logger.Write(lEntry); Logger.Write("[Exit]Exit Method"); } } }
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { object actualData = data; if (data is XmlLogEntry) { XmlLogEntry logEntryXml = data as XmlLogEntry; if (logEntryXml.Xml != null) { actualData = logEntryXml.Xml; } else { actualData = GetXml(logEntryXml); } } else if (data is LogEntry) { actualData = GetXml(data as LogEntry); } base.TraceData(eventCache, source, eventType, id, actualData); }
private void RunSqlInternal(String pSql, DBManagerParams pDBManagerParams, DBManagerConnection pTransac) { ////Lots of code, and below is the log XmlDocument doc = new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); using (XmlWriter xml = nav.AppendChild()) { xml.WriteStartElement("log"); xml.WriteAttributeString("Método", "RunSql"); xml.WriteString(pSql); xml.WriteEndElement(); xml.Flush(); } XmlLogEntry entry = new XmlLogEntry(); entry.Xml = nav; entry.Priority = 1; entry.Categories = new String[] { "DB" }; entry.Severity = TraceEventType.Information; Logger.Write(entry); oCommand.ExecuteNonQuery(); }
/// <summary> /// Writes trace information, a data object and event information through the Logging Block. /// </summary> /// <param name="eventCache">A <see cref="TraceEventCache"/> object that contains the current process ID, thread ID, and stack trace information.</param> /// <param name="source">An identification of the source of the trace request.</param> /// <param name="eventType">One of the <see cref="TraceEventType"/> values specifying the type of event that has caused the trace.</param> /// <param name="id">A numeric identifier for the event.</param> /// <param name="data">The trace data to emit.</param> public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { Dictionary<string, object> properties = new Dictionary<string, object>(); properties.Add(TraceEventCacheKey, eventCache); LogEntry logEntry = null; if (data is XPathNavigator) { XPathNavigator xmlData = data as XPathNavigator; List<string> categories = new List<string>(); categories.Add(source); foreach (string xpathQuery in this.CategoriesXPathQueries) { XPathNodeIterator nodeIterator = xmlData.Select(xpathQuery, this.NamespaceManager); foreach (object value in nodeIterator) { categories.Add(((XPathNavigator)value).Value); } } XmlLogEntry xmlLogEntry = new XmlLogEntry(data, categories, int.MaxValue, id, eventType, null, properties); xmlLogEntry.Xml = xmlData; logEntry = xmlLogEntry; } else if (data is LogEntry) { logEntry = data as LogEntry; } else { logEntry = new LogEntry(data, string.IsNullOrEmpty(source) ? new string[0] : new string[] { source }, int.MaxValue, id, eventType, null, properties); } Logger.Write(logEntry); }
//--------------------------------------------------------------------- public void UpateRecord(String name, Int32 age) { MethodBase mb = MethodBase.GetCurrentMethod(); Logger.Write(String.Format("[Enter]{0}", mb.Name)); try { Logger.Write(String.Format("Message1: {0} - {1}", name, age)); Logger.Write("Information", "General", 0, 0, TraceEventType.Information); Logger.Write("Critical", "General", 0, 0, TraceEventType.Critical); Logger.Write("Error", "General", 0, 0, TraceEventType.Error); Logger.Write("Warning", "General", 0, 0, TraceEventType.Warning); // send an XML log XmlLogEntry xmlEntry = new XmlLogEntry(); xmlEntry.Categories.Add("General"); xmlEntry.Severity = TraceEventType.Information; xmlEntry.Message = "Sample XML"; xmlEntry.Xml = GetSampleXmlDocumet().CreateNavigator(); Logger.Write(xmlEntry); // message with extension LogEntry lEntry = new LogEntry(); lEntry.Categories.Add("General"); lEntry.Severity = TraceEventType.Information; lEntry.Message = "message with extended properties."; lEntry.ExtendedProperties["ClientId"] = 1234; lEntry.ExtendedProperties["CompanyId"] = 7895; lEntry.ExtendedProperties["State"] = "CA"; Logger.Write(lEntry); } finally { Logger.Write(String.Format("[Exit]{0}", mb.Name)); } }
public static XmlLogEntry CreateXmlLogEntry(string xml, string[] categories) { XmlLogEntry entry = new XmlLogEntry(); FillLogEntry(entry); entry.Categories = new List<string>(categories); entry.Xml = new XPathDocument(new StringReader(xml)).CreateNavigator(); return entry; }
public static void AssertXmlLogEntries(XmlLogEntry xmlLogEntry, XmlLogEntry anotherXmlLogEntry) { AssertLogEntries(xmlLogEntry, anotherXmlLogEntry); Assert.AreEqual(xmlLogEntry.Xml.InnerXml, anotherXmlLogEntry.Xml.InnerXml); }