TraceSwitch.TraceInfo 属性
获取一个值,它指示开关是否允许信息性消息。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
Public ReadOnly Property TraceInfo As Boolean
用法
Dim instance As TraceSwitch
Dim value As Boolean
value = instance.TraceInfo
public bool TraceInfo { get; }
public:
property bool TraceInfo {
bool get ();
}
/** @property */
public boolean get_TraceInfo ()
public function get TraceInfo () : boolean
属性值
如果 Level 属性设置为 TraceLevel.Info 或 TraceLevel.Verbose,则为 true;否则为 false。
备注
可以将 TraceError、TraceWarning、TraceInfo 和 TraceVerbose 属性与 Debug 和 Trace 类结合使用,发出具有指定或更高重要性的所有消息。当 Level 属性设置为 TraceLevel.Warning 时,发出信息性消息、警告和错误处理消息。
示例
下面的代码示例创建一个新的 TraceSwitch 并使用此开关确定是否发出错误信息。此开关在类级别创建。如果 Level 属性设置为 TraceLevel.Info 或更高级别,MyMethod
会写入第一条错误信息。但是,当 Level 小于 TraceLevel.Verbose 时,MyMethod
将不写入第二条错误信息。
' Class-level declaration.
' Create a TraceSwitch to use in the entire application.
Private Shared mySwitch As New TraceSwitch("General", "Entire Application")
Public Shared Sub MyMethod()
' Write the message if the TraceSwitch level is set to Info or higher.
If mySwitch.TraceInfo Then
Console.WriteLine("My error message.")
End If
' Write the message if the TraceSwitch level is set to Verbose.
If mySwitch.TraceVerbose Then
Console.WriteLine("My second error message.")
End If
End Sub
Public Shared Sub Main()
' Run the method that prints error messages based on the switch level.
MyMethod()
End Sub
//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 Info or higher.
if(mySwitch.TraceInfo)
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();
}
// Class-level declaration.
/* Create a TraceSwitch to use in the entire application.*/
private:
static TraceSwitch^ mySwitch = gcnew TraceSwitch( "General", "Entire Application" );
public:
static void MyMethod()
{
// Write the message if the TraceSwitch level is set to Info or higher.
if ( mySwitch->TraceInfo )
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." );
}
static void main()
{
// Run the method that prints error messages based on the switch level.
MyMethod();
}
// Class-level declaration.
/* Create a TraceSwitch to use in the entire application.
*/
private static TraceSwitch mySwitch =
new TraceSwitch("General", "Entire Application");
public static void MyMethod()
{
// Write the message if the TraceSwitch level is set to Info or higher.
if (mySwitch.get_TraceInfo()) {
Console.WriteLine("My error message.");
}
// Write the message if the TraceSwitch level is set to Verbose.
if (mySwitch.get_TraceVerbose()) {
Console.WriteLine("My second error message.");
}
} //MyMethod
public static void main(String[] args)
{
// Run the method that prints error messages based on the switch level.
MyMethod();
} //main
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
TraceSwitch 类
TraceSwitch 成员
System.Diagnostics 命名空间
TraceSwitch 类
Switch 类
TraceLevel 枚举
Debug 类
Trace 类