本文整理匯總了C#中System.Diagnostics.XmlWriterTraceListener類的典型用法代碼示例。如果您正苦於以下問題:C# XmlWriterTraceListener類的具體用法?C# XmlWriterTraceListener怎麽用?C# XmlWriterTraceListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XmlWriterTraceListener類屬於System.Diagnostics命名空間,在下文中一共展示了XmlWriterTraceListener類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Diagnostics;
class testClass
{
static void Main()
{
File.Delete("NotEscaped.xml");
TraceSource ts = new TraceSource("TestSource");
ts.Listeners.Add(new XmlWriterTraceListener("NotEscaped.xml"));
ts.Switch.Level = SourceLevels.All;
string testString = "<Test><InnerElement Val=\"1\" /><InnerElement Val=\"Data\"/><AnotherElement>11</AnotherElement></Test>";
XmlTextReader myXml = new XmlTextReader(new StringReader(testString));
XPathDocument xDoc = new XPathDocument(myXml);
XPathNavigator myNav = xDoc.CreateNavigator();
ts.TraceData(TraceEventType.Error, 38, myNav);
ts.Flush();
ts.Close();
File.Delete("Escaped.xml");
TraceSource ts2 = new TraceSource("TestSource2");
ts2.Listeners.Add(new XmlWriterTraceListener("Escaped.xml"));
ts2.Switch.Level = SourceLevels.All;
ts2.TraceData(TraceEventType.Error, 38, testString);
ts2.Flush();
ts2.Close();
}
}