Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DefaultTraceListener Class

Provides the default output methods and behavior for tracing.

For a list of all members of this type, see DefaultTraceListener Members.

System.Object
   System.MarshalByRefObject
      System.Diagnostics.TraceListener
         System.Diagnostics.DefaultTraceListener

[Visual Basic]
<ComVisible(False)>
Public Class DefaultTraceListener
   Inherits TraceListener
[C#]
[ComVisible(false)]
public class DefaultTraceListener : TraceListener
[C++]
[ComVisible(false)]
public __gc class DefaultTraceListener : public TraceListener
[JScript]
public
   ComVisible(false)
class DefaultTraceListener extends TraceListener

Thread Safety

This type is safe for multithreaded operations.

Remarks

This class is automatically added to the Debug.Listeners and to the Trace.Listeners collections.

By default, Write and WriteLine methods emit the message to the OutputDebugString and to the Log method. For information about the OutputDebugString API, see the Platform SDK or MSDN.

The Fail method, by default, displays a message box when the application is running in a user interface mode; it also emits the message using WriteLine.

You must enable tracing or debugging to use a switch. The following syntax is compiler specific. If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.

  • To enable debugging in C#, add the /d:DEBUG flag to the compiler command line when you compile your code, or add #define DEBUG to the top of your file. In Visual Basic, add the /d:DEBUG=True flag to the compiler command line.
  • To enable tracing using in C#, add the /d:TRACE flag to the compiler command line when you compile your code, or add #define TRACE to the top of your file. In Visual Basic, add the /d:TRACE=True flag to the compiler command line.

To set the level of your listener, edit the configuration file that corresponds to the name of your application. Within this file, you can add a listener, set its type and set its parameter, remove a listener, or clear all the listeners previously set by the application. The configuration file should be formatted similar to the following example:

<configuration>
<system.diagnostics>
    <switches>
        <add name="MagicTraceSwitch" value="3" />
    </switches>
    <trace autoflush="false" indentsize="4">
        <listeners>
           <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\myListener.log" />
           <remove type="System.Diagnostics.DefaultTraceListener"/> 
        </listeners>
    </trace>
</system.diagnostics>
</configuration>

Requirements

Namespace: System.Diagnostics

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

DefaultTraceListener Members | System.Diagnostics Namespace | TraceListener | TextWriterTraceListener | Debug | Trace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.