System.Diagnostics.DefaultTraceListener Class

Assembly: System.dll
Namespace: System.Diagnostics
Summary
Provides the default output methods and behavior for tracing.
C# Syntax:
public class DefaultTraceListener : 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, DefaultTraceListener.Write and DefaultTraceListener.WriteLine methods emit the message to the OutputDebugString and to the Debugger.Log method. For information about the OutputDebugString API, see "OutputDebugString" in the Platform SDK or MSDN.

The DefaultTraceListener.Fail method, by default, displays a message box when the application is running in a user interface mode; it also emits the message using DefaultTraceListener.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 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,System" initializeData="c:\myListener.log" />
                     <remove type="System.Diagnostics.DefaultTraceListener,System"/> 
                  </listeners>
              </trace>
          </system.diagnostics>
          </configuration>
        
See also:
System.Diagnostics Namespace | TraceListener | TextWriterTraceListener | Debug | Trace

System.Diagnostics.DefaultTraceListener Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the DefaultTraceListener class with "Default" as its TraceListener.Name.
Public Properties
AssertUiEnabled Read-write

Gets or sets whether the application is running in user-interface mode.
IndentLevel
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.IndentLevel


Gets or sets the indent level.
IndentSize
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.IndentSize


Gets or sets the number of spaces in an indent.
LogFileName Read-write

Gets or sets name of a log file to write trace or debug messages to.
Name
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.Name


Gets or sets a name for this TraceListener.
Public Methods
Close
(inherited from System.Diagnostics.TraceListener)
See base class member description: System.Diagnostics.TraceListener.Close


When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Dispose
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Dispose()

See base class member description: System.Diagnostics.TraceListener.Dispose


Releases all resources used by the TraceListener.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
Fail Overloaded:
Fail(string message)

Overridden:
Emits or displays a message and a stack trace for an assertion that always fails.
Fail Overloaded:
Fail(string message, string detailMessage)

Overridden:
Emits or displays detailed messages and a stack trace for an assertion that always fails.
Flush
(inherited from System.Diagnostics.TraceListener)
See base class member description: System.Diagnostics.TraceListener.Flush


When overridden in a derived class, flushes the output buffer.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(object o)

See base class member description: System.Diagnostics.TraceListener.Write


Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
Write Overloaded:
Write(string message)

Overridden:
Writes the output to the OutputDebugString and the Debugger.Log method.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(object o, string category)

See base class member description: System.Diagnostics.TraceListener.Write


Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
Write
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Write(string message, string category)

See base class member description: System.Diagnostics.TraceListener.Write


Writes a category name and a message to the listener you create when you implement the TraceListener class.
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(object o)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
WriteLine Overloaded:
WriteLine(string message)

Overridden:
Writes the output to the OutputDebugString and the Debugger.Log method followed by a carriage return and a line feed (\r\n).
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(object o, string category)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
WriteLine
(inherited from System.Diagnostics.TraceListener)
Overloaded:
WriteLine(string message, string category)

See base class member description: System.Diagnostics.TraceListener.WriteLine


Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.
Protected Properties
NeedIndent
(inherited from System.Diagnostics.TraceListener)
Read-write

See base class member description: System.Diagnostics.TraceListener.NeedIndent


Gets or sets a value indicating whether to indent the output.
Protected Methods
Dispose
(inherited from System.Diagnostics.TraceListener)
Overloaded:
Dispose(bool disposing)

See base class member description: System.Diagnostics.TraceListener.Dispose


Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
WriteIndent
(inherited from System.Diagnostics.TraceListener)
See base class member description: System.Diagnostics.TraceListener.WriteIndent


Writes the indent to the listener you create when you implement this class, and resets the TraceListener.NeedIndent property to false.

Hierarchy:


System.Diagnostics.DefaultTraceListener Member Details

ctor #1
Summary
Initializes a new instance of the DefaultTraceListener class with "Default" as its TraceListener.Name.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public DefaultTraceListener();
See also:
TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: AssertUiEnabled (read-write)
Summary
Gets or sets whether the application is running in user-interface mode.
C# Syntax:
public bool AssertUiEnabled {get; set;}

Return to top


Property: IndentLevel (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.IndentLevel

Summary
Gets or sets the indent level.
C# Syntax:
public int IndentLevel {get; set;}
Remarks
This property is stored on per-thread/per-request basis.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: IndentSize (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.IndentSize

Summary
Gets or sets the number of spaces in an indent.
C# Syntax:
public int IndentSize {get; set;}
Remarks
The property is stored on per-thread/per-request basis.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: LogFileName (read-write)
Summary
Gets or sets name of a log file to write trace or debug messages to.
C# Syntax:
public string LogFileName {get; set;}

Return to top


Property: Name (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.Name

Summary
Gets or sets a name for this TraceListener.
C# Syntax:
public virtual string Name {get; set;}
Remarks
The name can be used to organize and access listeners in a TraceListenerCollection collection.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Property: NeedIndent (read-write)
Inherited
See base class member description: System.Diagnostics.TraceListener.NeedIndent

Summary
Gets or sets a value indicating whether to indent the output.
C# Syntax:
protected bool NeedIndent {get; set;}
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: Close()
Inherited
See base class member description: System.Diagnostics.TraceListener.Close

Summary
When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.
C# Syntax:
public virtual void Close();
Remarks
Use this method when the output is going to a file, such as to the TextWriterTraceListener. After a call to this method, you must reinitialize the object.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Overloaded Method: Dispose()
Inherited
See base class member description: System.Diagnostics.TraceListener.Dispose

Summary
Releases all resources used by the TraceListener.
C# Syntax:
public void Dispose();
Implements:
IDisposable.Dispose
Remarks
Calling TraceListener.Dispose allows the resources used by the TraceListener. to be reallocated for other purposes. For more information about TraceListener.Dispose, see the conceptual topic at MSDN: cleaningupunmanagedresources.
See also:
MSDN: cleaningupunmanagedresources

Return to top


Overloaded Method: Dispose(
   bool disposing
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Dispose

Summary
Releases the unmanaged resources used by the TraceListener and optionally releases the managed resources.
C# Syntax:
protected virtual void Dispose(
   bool disposing
);
Parameters:

disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks
This method is called by the public Dispose method and the Object.Finalize method.Dispose() invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Object.Finalize invokes Dispose with disposing set to false.

When the disposing parameter is true, this method releases all resources held by any managed objects that this TraceListener references. This method invokes the Dispose() method of each referenced object.



Notes to inheritors: Dispose can be called multiple times by other objects. When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. For more information about how to implement Dispose, see the conceptual topic at MSDN: implementingdisposemethod.

For more information about Dispose and Finalize, see the conceptual topic at MSDN: cleaningupunmanagedresources and the conceptual topic at MSDN: overridingfinalizemethod.

See also:
MSDN: implementingdisposemethod | MSDN: cleaningupunmanagedresources

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Fail(
   string message
)
Summary
Emits or displays a message and a stack trace for an assertion that always fails.
C# Syntax:
public override void Fail(
   string message
);
Parameters:

message

The message to emit or display.

Remarks
By default, this method outputs the message parameter and a stack trace to a message box (when the application runs in user-interface mode) and to the instance of this class.
See also:
TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Fail(
   string message,
   string detailMessage
)
Summary
Emits or displays detailed messages and a stack trace for an assertion that always fails.
C# Syntax:
public override void Fail(
   string message,
   string detailMessage
);
Parameters:

message

The message to emit or display.

detailMessage

The detailed message to emit or display.

Remarks
By default this method outputs the message parameter, the detailedMessage parameter, and a stack trace to a message box (when the application runs in user-interface mode) and to the instance of this class.
See also:
TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~DefaultTraceListener();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Flush()
Inherited
See base class member description: System.Diagnostics.TraceListener.Flush

Summary
When overridden in a derived class, flushes the output buffer.
C# Syntax:
public virtual void Flush();
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Write(
   object o
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   object o
);
Parameters:

o

An Object whose fully qualified class name you want to write.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Write(
   string message
)
Summary
Writes the output to the OutputDebugString and the Debugger.Log method.
C# Syntax:
public override void Write(
   string message
);
Parameters:

message

The message to write to the OutputDebugString and the Debugger.Log.

Remarks
For information about the OutputDebugString API, see "OutputDebugString" in the Platform SDK or MSDN.
See also:
TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Write(
   object o,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   object o,
   string category
);
Parameters:

o

An Object whose fully qualified class name you want to write.

category

A category name used to organize the output.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: Write(
   string message,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.Write

Summary
Writes a category name and a message to the listener you create when you implement the TraceListener class.
C# Syntax:
public virtual void Write(
   string message,
   string category
);
Parameters:

message

A message to write.

category

A category name used to organize the output.

See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Method: WriteIndent()
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteIndent

Summary
Writes the indent to the listener you create when you implement this class, and resets the TraceListener.NeedIndent property to false.
C# Syntax:
protected virtual void WriteIndent();
Remarks
Writes the indent and resets TraceListener.NeedIndent to false. Call this method if TraceListener.NeedIndent is true, when you are overloading TraceListener.Write and TraceListener.WriteLine. By default, this method uses blank spaces for indentation.
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   object o
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   object o
);
Parameters:

o

An Object whose fully qualified class name you want to write.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   string message
)
Summary
Writes the output to the OutputDebugString and the Debugger.Log method followed by a carriage return and a line feed (\r\n).
C# Syntax:
public override void WriteLine(
   string message
);
Parameters:

message

The message to write to the OutputDebugString and the Debugger.Log.

Remarks
The default line terminator is a carriage return followed by a line feed (\r\n).

For information about the OutputDebugString API, see "OutputDebugString" in the Platform SDK or MSDN.

This method sets TraceListener.NeedIndent to true.

See also:
TraceListener | DefaultTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   object o,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes a category name and the value of the object's Object.ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   object o,
   string category
);
Parameters:

o

An Object whose fully qualified class name you want to write.

category

A category name used to organize the output.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Overloaded Method: WriteLine(
   string message,
   string category
)
Inherited
See base class member description: System.Diagnostics.TraceListener.WriteLine

Summary
Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.
C# Syntax:
public virtual void WriteLine(
   string message,
   string category
);
Parameters:

message

A message to write.

category

A category name used to organize the output.

Remarks
The typical line terminator you might implement is a carriage return followed by a line feed (\r\n).
See also:
TraceListener | DefaultTraceListener | EventLogTraceListener | TextWriterTraceListener | Debug | Trace

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.