本文整理汇总了C#中System.Diagnostics.TraceSwitch类的典型用法代码示例。如果您正苦于以下问题:C# TraceSwitch类的具体用法?C# TraceSwitch怎么用?C# TraceSwitch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceSwitch类属于System.Diagnostics命名空间,在下文中一共展示了TraceSwitch类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceSwitch
//Class-level declaration.
/* Create a TraceSwitch to use in the entire application.*/
static TraceSwitch mySwitch = new TraceSwitch("General", "Entire Application");
static public void MyMethod() {
// Write the message if the TraceSwitch level is set to Error or higher.
if(mySwitch.TraceError)
Console.WriteLine("My error message.");
// Write the message if the TraceSwitch level is set to Verbose.
if(mySwitch.TraceVerbose)
Console.WriteLine("My second error message.");
}
public static void Main(string[] args) {
// Run the method that prints error messages based on the switch level.
MyMethod();
}
示例2: TraceSwitch
private static TraceSwitch appSwitch = new TraceSwitch("mySwitch",
"Switch in config file");
public static void Main(string[] args)
{
//...
Console.WriteLine("Trace switch {0} configured as {1}",
appSwitch.DisplayName, appSwitch.Level.ToString());
if (appSwitch.TraceError)
{
//...
}
}
示例3: new TraceSwitch
//引入命名空间
using System;
using System.Diagnostics;
class TracingExample
{
static void Main(string[] args)
{
TraceSwitch General = new TraceSwitch("General", "Application Switch");
Trace.WriteLineIf(General.TraceError, "General - Error Tracing Enabled");
Trace.WriteLineIf(General.TraceWarning, "General - Warning Tracing Enabled");
Trace.WriteLineIf(General.TraceInfo, "General - Info Tracing Enabled");
Trace.WriteLineIf(General.TraceVerbose, "General - Verbose Tracing Enabled");
}
}
/*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="General" value="1" />
</switches>
</system.diagnostics>
</configuration>
*/