System [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.3300.0 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object

You can use the properties and methods in the class to instrument release builds. Instrumentation allows you to monitor the health of your application running in real-life settings. Tracing helps you isolate problems and fix them without disturbing a running system.

This class provides methods to display an dialog box, and to emit an assertion that will always . This class provides write methods in the following variations: , , , and .

The and classes provide means to dynamically control the tracing output. You can modify the values of these switches without recompiling your application. For information on using the configuration file to set a switch, see the class and the How to: Configure Trace Switches topic.

You can customize the tracing output's target by adding instances to or removing instances from the collection. The collection is shared by both the and the classes; adding a trace listener to either class adds the listener to both. By default, trace output is emitted using the class.

Adding a trace listener to the collection can cause an exception to be thrown while tracing, if a resource used by the trace listener is not available. The conditions and the exception thrown depend on the trace listener and cannot be enumerated in this topic. It may be useful to place calls to the methods in try/catch blocks to detect and handle any exceptions from trace listeners.

If you add trace listeners to partially trusted code, you will get a exception, because adding trace listeners requires permission. To trace partially trusted code that is running in a sandbox in Visual Studio, do not add trace listeners. Instead, view the and messages in the Output window.

The class provides properties to get or set the level of , the , and whether to after each write.

To set the and for , you can edit the configuration file that corresponds to the name of your application. The configuration file should be formatted like the following example:

`<configuration> <system.diagnostics> <trace autoflush="false" indentsize="3" /> </system.diagnostics> </configuration>`

The attribute is applied to the methods of . Compilers that support ignore calls to these methods unless "TRACE" is defined as a conditional compilation symbol. Refer to a compiler's documentation to determine whether is supported and the syntax for defining a conditional compilation symbol.

In Visual Studio projects, by default, the "DEBUG" conditional compilation symbol is defined for debug builds, and the "TRACE" symbol is defined for both debug and release builds. For information about how to disable this behavior, see the Visual Studio documentation.

To define the "TRACE" conditional compilation symbol in C#, add the /d:TRACE option to the compiler command line when you compile your code using a command line, or add #define TRACE to the top of your file. In Visual Basic, add the /d:TRACE=True option to the compiler command line or add #Const TRACE=True to the file.

is not supported by the C++ compiler. To provide equivalent functionality, you must enclose calls to the methods of in an #if defined(TRACE) ... #endif block, and add the /DTRACE option to the compiler command line or add #define TRACE to the file.

Provides a set of methods and properties that help you trace the execution of your code. This class cannot be inherited.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  Use the method if you want to do assertions in release builds. The method works only in debug builds. For more information, see Assertions in Managed Code.

  Typically, the method is used to identify logic errors during program development. evaluates the condition. If the result is false, it sends a failure message to the collection. You can customize this behavior by adding a to, or removing one from, the collection.

  When the application runs in user-interface mode, it displays a message box that shows the call stack with file and line numbers. The message box contains three buttons: Abort, Retry, and Ignore. Clicking the Abort button terminates the application. Clicking Retry sends you to the code in the debugger if your application is running in a debugger, or offers to open a debugger if it is not. Clicking Ignore continues with the next instruction in the code.

  The display of the message box depends on the presence of the . If the is not in the collection, the message box is not displayed. The can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the method on the property (System.Diagnostics.Trace.Listeners.Clear()).

  You can change the behavior of the in the configuration file that corresponds to the name of your application. In this file, you can enable and disable the assert message box or set the property. The configuration file should be formatted as follows:

  `<configuration> <system.diagnostics> <switches> <add name="mySwitch" value="4"/> </switches> <trace autoflush="false" indentsize="4"/> <assert assertuienabled="true" logfilename=".\TraceLog.txt"/> </system.diagnostics> </configuration>`

  Checks for a condition; if the condition is false, displays a message box that shows the call stack.

  The conditional expression to evaluate. If the condition is true, a failure message is not sent and the message box is not displayed.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  Use the method if you want to do assertions in release builds. The method works only in debug builds. For more information, see Assertions in Managed Code.

  Typically, the method is used to identify logic errors during program development. evaluates the condition. If the result is false, it sends the specified diagnostic message to the collection. You can customize this behavior by adding a to, or removing one from, the collection.

  When the application runs in user-interface mode, it displays a message box that shows the call stack with file and line numbers. The message box contains three buttons: Abort, Retry, and Ignore. Clicking the Abort button terminates the application. Clicking Retry sends you to the code in the debugger if your application is running in a debugger, or offers to open a debugger if it is not. Clicking Ignore continues with the next instruction in the code.

  The display of the message box depends on the presence of the . If the is not in the collection, the message box is not displayed. The can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the method on the property (System.Diagnostics.Trace.Listeners.Clear()).

  You can change the behavior of the in the configuration file that corresponds to the name of your application. In this file, you can enable and disable the assert message box or set the property. The configuration file should be formatted as follows:

  `<configuration> <system.diagnostics> <switches> <add name="mySwitch" value="4"/> </switches> <trace autoflush="false" indentsize="4"/> <assert assertuienabled="true" logfilename=".\TraceLog.txt"/> </system.diagnostics> </configuration>`

  Checks for a condition; if the condition is false, outputs a specified message and displays a message box that shows the call stack.

  The conditional expression to evaluate. If the condition is true, the specified message is not sent and the message box is not displayed. The message to send to the collection.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `` ``

  Use the method if you want to do assertions in release builds. The method works only in debug builds. For more information, see Assertions in Managed Code.

  Typically, the method is used to identify logic errors during program development. evaluates the condition. If the result is false, it sends the specified diagnostic message and detailed message to the collection. You can customize this behavior by adding a to, or removing one from, the collection.

  When the application runs in user-interface mode, it displays a message box that shows the call stack with file and line numbers. The message box contains three buttons: Abort, Retry, and Ignore. Clicking the Abort button terminates the application. Clicking Retry sends you to the code in the debugger if your application is running in a debugger, or offers to open a debugger if it is not. Clicking Ignore continues with the next instruction in the code.

  The display of the message box depends on the presence of the . If the is not in the collection, the message box is not displayed. The can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the method on the property (System.Diagnostics.Trace.Listeners.Clear()).

  You can change the behavior of the in the configuration file that corresponds to the name of your application. In this file, you can enable and disable the assert message box or set the property. The configuration file should be formatted as follows:

  `<configuration> <system.diagnostics> <switches> <add name="mySwitch" value="4"/> </switches> <trace autoflush="false" indentsize="4"/> <assert assertuienabled="true" logfilename=".\TraceLog.txt"/> </system.diagnostics> </configuration>`

  Checks for a condition; if the condition is false, outputs two specified messages and displays a message box that shows the call stack.

  The conditional expression to evaluate. If the condition is true, the specified messages are not sent and the message box is not displayed. The message to send to the collection. The detailed message to send to the collection.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean Whether or not the objects should be ed after each write.

  The default is false.

  Flushing the stream will not flush its underlying encoder unless you explicitly call or . Setting to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

  To set the and for , you can also edit the configuration file that corresponds to the name of your application. The configuration file should be formatted like the following example:

  `<configuration> <system.diagnostics> <trace autoflush="false" indentsize="3" /> </system.diagnostics> </configuration>`

  Gets or sets whether should be called on the after every write.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void

  Use this method when the output is going to a file, such as to the .

  Flushing the stream will not flush its underlying encoder unless you explicitly call or . Setting to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

  Flushes the output buffer, and then closes the .

- Property
  2.0.0.0
  4.0.0.0
  System.Diagnostics.CorrelationManager To be added.

  This is an advanced property that most applications should not have occasion to use.

  The class provides methods used to store a logical operation identity in a thread-bound context and automatically tag each trace event generated by the thread with the stored identity.

  Gets the correlation manager for the thread for this trace.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  The default behavior for the default trace listener is to output the parameter to a message box when the application runs in user-interface mode, and to the instances in the collection.

  The display of the message box is dependent on the presence of the . If the is not in the collection, the message box is not displayed. The can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the method on the property (System.Diagnostics.Trace.Listeners.Clear()).

  You can customize this behavior by adding a to, or by removing one from, the collection.

  Emits the specified error message.

  A message to emit.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  The default behavior is for the default trace listener to output the parameter and the parameter to a message box when the application runs in user-interface mode, and to the instances in the collection.

  The display of the message box is dependent on the presence of the . If the is not in the collection, the message box is not displayed. The can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the method on the property (System.Diagnostics.Trace.Listeners.Clear()).

  You can customize this behavior by adding a to, or by removing one from, the collection.

  Emits an error message, and a detailed error message.

  A message to emit. A detailed message to emit.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void

  Flushing the stream will not flush its underlying encoder unless you explicitly call or . Setting to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

  Flushes the output buffer, and causes buffered data to be written to the .

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void

  This is equivalent to incrementing by one.

  Increases the current by one.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 The indent level.

  The property represents the number of times the indent of size is applied. This property is stored on per-thread/per-request basis.

  Gets or sets the indent level.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 The indent size.

  A interprets this number as spaces. An ignores this value.

  This property is stored on per-thread/per-request basis.

  To set the and for , you can also edit the configuration file that corresponds to the name of your application. The configuration file should be formatted like the following example:

  `<configuration> <system.diagnostics> <trace autoflush="false" indentsize="3" /> </system.diagnostics> </configuration>`

  Gets or sets the number of spaces in an indent.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.TraceListenerCollection The list of objects to forward messages to.

  The listeners produce formatted output from the trace output. By default, the collection contains an instance of the class. If you want to remove the default listener, call the method, and pass it the instance of the . To redirect output to the console window, add an instance of the class.

  The collection is shared by both the and the classes; adding a trace listener to either class adds the listener to both.

  Gets the collection of listeners that is monitoring the trace output.

- Method
  2.0.0.0
  4.0.0.0
  System.MonoNotSupported("")
  System.Void

  Trace configuration data is captured when the application is started. If the configuration data is changed after the application is started, call the method to update the trace configuration data.

  Refreshes the trace configuration data.

- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  calls the TraceEvent method for each trace listener, with the trace event type , passing the informative message as the message string.

  Writes an error message to the trace listeners in the collection using the specified message.

  The informative message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `System.ParamArray` To be added.

  calls the TraceEvent methods in the trace listeners with the trace event type , passing the message content as an object array with formatting information. See the method for more information about the and parameters.

  Writes an error message to the trace listeners in the collection using the specified array of objects and formatting information.

  An object array containing zero or more objects to format.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  calls the TraceEvent method for each trace listener, with the trace event type , passing the informative message as the message string.

  Writes an informational message to the trace listeners in the collection using the specified message.

  The informative message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `System.ParamArray` To be added.

  calls the TraceEvent methods in the trace listeners with the trace event type , passing the message content as an object array with formatting information. See the method for more information about the and parameters.

  Writes an informational message to the trace listeners in the collection using the specified array of objects and formatting information.

  An object array containing zero or more objects to format.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  calls the TraceEvent method for each trace listener with the trace event type , passing the informative message as the message string.

  Writes a warning message to the trace listeners in the collection using the specified message.

  The informative message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `System.ParamArray` To be added.

  calls the TraceEvent methods in the trace listeners with the trace event type , passing the message content as an object array with formatting information. See the method for more information about the and parameters.

  Writes a warning message to the trace listeners in the collection using the specified array of objects and formatting information.

  An object array containing zero or more objects to format.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void

  This is equivalent to decrementing by one.

  Decreases the current by one.

- Property
  2.0.0.0
  4.0.0.0
  System.Boolean To be added.

  The global lock is always used if the trace listener is not thread safe, regardless of the value of . The property is used to determine if the listener is thread safe. The global lock is not used only if the value of is false and the value of is true. The default behavior is to use the global lock.

  To set the for , you can also edit the configuration file that corresponds to the name of your application. The configuration file should be formatted like the following example:

  `<configuration> <system.diagnostics> <trace useGlobalLock="false" /> </system.diagnostics> </configuration>`

  Gets or sets a value indicating whether the global lock should be used.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  ASP.NET supplies tracing functionality tailored for Web pages. To write trace messages in ASP.NET pages, use the property.

  By default, in code associated with an ASP.NET Web page, the statement Trace.Write("...") is a call to the method of the property. To use the class in Web pages, you must include the namespace, for example, System.Diagnostics.Trace.Write("...").

  Writes the value of the object's method to the trace listeners in the collection.

  An whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  ASP.NET supplies tracing functionality tailored for Web pages. To write trace messages in ASP.NET pages, use the property.

  By default, in code associated with an ASP.NET Web page, the statement Trace.Write("...") is a call to the method of the property. To use the class in Web pages, you must include the namespace, for example, System.Diagnostics.Trace.Write("...").

  Writes a message to the trace listeners in the collection.

  A message to write.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  ASP.NET supplies tracing functionality tailored for Web pages. To write trace messages in ASP.NET pages, use the property.

  By default, in code associated with an ASP.NET Web page, the statement Trace.Write("...") is a call to the method of the property. To use the class in Web pages, you must include the namespace, for example, System.Diagnostics.Trace.Write("...").

  Writes a category name and the value of the object's method to the trace listeners in the collection.

  An name is sent to the . A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  ASP.NET supplies tracing functionality tailored for Web pages. To write trace messages in ASP.NET pages, use the property.

  By default, in code associated with an ASP.NET Web page, the statement Trace.Write("...") is a call to the method of the property. To use the class in Web pages, you must include the namespace, for example, System.Diagnostics.Trace.Write("...").

  Writes a category name and a message to the trace listeners in the collection.

  A message to write. A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes the value of the object's method to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. An whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes a message to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. A message to write.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and the value of the object's method to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. An whose name is sent to the . A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and message to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. A message to write. A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes the value of the object's method to the trace listeners in the collection.

  An whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes a message to the trace listeners in the collection.

  A message to write.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and the value of the object's method to the trace listeners in the collection.

  An whose name is sent to the . A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and message to the trace listeners in the collection.

  A message to write. A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes the value of the object's method to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. An whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` ``

  By default, the output is written to an instance of .

  This method calls the method of the trace listener.

  Writes a message to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. A message to write.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and the value of the object's method to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. An whose name is sent to the . A category name used to organize the output.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("TRACE")
  System.Void `` `` ``

  By default, the output is written to an instance of .

  The parameter can be used to group output messages.

  This method calls the method of the trace listener.

  Writes a category name and message to the trace listeners in the collection if a condition is true.

  true to cause a message to be written; otherwise, false. A message to write. A category name used to organize the output.