本文整理匯總了C#中System.Diagnostics.EventSchemaTraceListener類的典型用法代碼示例。如果您正苦於以下問題:C# EventSchemaTraceListener類的具體用法?C# EventSchemaTraceListener怎麽用?C# EventSchemaTraceListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EventSchemaTraceListener類屬於System.Diagnostics命名空間,在下文中一共展示了EventSchemaTraceListener類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
#define NOCONFIGFILE
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Diagnostics;
class testClass
{
[STAThreadAttribute]
static void Main()
{
File.Delete("TraceOutput.xml");
TraceSource ts = new TraceSource("TestSource");
#if NOCONFIGFILE
//ts.Listeners.Add(new EventSchemaTraceListener("TraceOutput.xml", "eventListener", 65536, TraceLogRetentionOption.LimitedCircularFiles, 20480000, 2));
ts.Listeners.Add(new EventSchemaTraceListener("TraceOutput.xml", "eventListener"));
ts.Listeners["eventListener"].TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ProcessId | TraceOptions.Timestamp;
#endif
ts.Switch.Level = SourceLevels.All;
string testString = "<Test><InnerElement Val=\"1\" /><InnerElement Val=\"Data\"/><AnotherElement>11</AnotherElement></Test>";
UnescapedXmlDiagnosticData unXData = new UnescapedXmlDiagnosticData(testString);
ts.TraceData(TraceEventType.Error, 38, unXData);
ts.TraceEvent(TraceEventType.Error, 38, testString);
Trace.Listeners.Add(new EventSchemaTraceListener("TraceOutput.xml"));
Trace.Write("test", "test");
Trace.Flush();
ts.Flush();
ts.Close();
DisplayProperties(ts);
Process.Start("notepad.exe", "TraceOutput.xml");
Console.WriteLine("Press the enter key to exit");
Console.ReadLine();
}
private static void DisplayProperties(TraceSource ts)
{
Console.WriteLine("IsThreadSafe? " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).IsThreadSafe);
Console.WriteLine("BufferSize = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).BufferSize);
Console.WriteLine("MaximumFileSize = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).MaximumFileSize);
Console.WriteLine("MaximumNumberOfFiles = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).MaximumNumberOfFiles);
Console.WriteLine("Name = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).Name);
Console.WriteLine("TraceLogRetentionOption = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).TraceLogRetentionOption);
Console.WriteLine("TraceOutputOptions = " + ((EventSchemaTraceListener)ts.Listeners["eventListener"]).TraceOutputOptions);
}
}