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

If you use methods in the class to print debugging information and check your logic with assertions, you can make your code more robust without impacting the performance and code size of your shipping product.

This class provides methods to display an dialog box, and to emit an assertion that will always fail. 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 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, the class emits trace output.

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.

You can modify the level of indentation using the method or the property. To modify the indent spacing, use the property. You can specify whether to automatically flush the output buffer after each write by setting the property to true.

To set the and for , you can edit the configuration file corresponding to the name of your application. The configuration file should be formatted as shown in the following example.

`<configuration> <system.diagnostics> <trace autoflush="true" indentsize="7" /> </system.diagnostics> </configuration>`

The attribute is applied to the methods of . Compilers that support ignore calls to these methods unless "DEBUG" 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 C# and Visual Basic 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. For information about conditional debugging in Visual C++, see Debug Class in Visual C++.

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

Provides a set of methods and properties that help debug your code. This class cannot be inherited.

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

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

  The Assert methods are not available for win8_appstore_long apps.

  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.

  win8_appname_long apps do not support modal dialog boxes, so they behave the same in user interface mode and non-user interface mode. The message is written to the active trace listeners in debugging mode, or no message is written in release mode.

  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> <assert assertuienabled="true" logfilename="c:\\myFile.log" /> </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("DEBUG")
  System.Void `` ``

  By default, the method works only in debug builds. Use the method if you want to do assertions in release 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> <assert assertuienabled="true" logfilename="c:\\myFile.log" /> </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("DEBUG")
  System.Void `` `` ``

  By default, the method works only in debug builds. Use the method if you want to do assertions in release 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> <assert assertuienabled="true" logfilename="c:\\myFile.log" /> </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.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Void `` `` `` `System.ParamArray`

  This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its text representation and embed that representation in a string. The resulting string is sent to the collection.

  By default, the method works only in debug builds. Use the method if you want to do assertions in release 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, The method is called and the string and array are passed in as parameters. then sends the specified text message and the formatted text 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 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 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> <assert assertuienabled="true" logfilename="c:\\myFile.log" /> </system.diagnostics> </configuration>`

  Checks for a condition; if the condition is false, outputs two messages (simple and formatted) 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 composite format string (see Remarks) to send to the collection. This message contains text intermixed with zero or more format items, which correspond to objects in the array. An object array that contains zero or more objects to format.
- 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 corresponding to the name of your application. The configuration file should be formatted as shown in the following example.

  `<configuration> <system.diagnostics> <trace autoflush="true" indentsize="7" /> </system.diagnostics> </configuration>`

  Gets or sets a value indicating 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("DEBUG")
  System.Void

  Use this method when the output goes 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 calls the Close method on each of the .

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

  The default behavior is that the outputs the message to a message box when the application is running 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 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("DEBUG")
  System.Void `` ``

  The default behavior is that the outputs the message to a message box when the application is running 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 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("DEBUG")
  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 write to the collection.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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.

  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.

  To set the and for , you can also edit the configuration file corresponding to the name of your application. The configuration file should be formatted as shown in the following example.

  `<configuration> <system.diagnostics> <trace autoflush="true" indentsize="7" /> </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 debug output. By default, the collection contains an instance of the class. 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 . To redirect output to a file or stream, add an instance of the .

  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 debug output.

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

  The default line terminator is a carriage return followed by a line feed. By default, the output is written to an instance of .

  Writes a message followed by a line terminator to the trace listeners in the collection.

  The message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Void `` `System.ParamArray`

  This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its text representation and embed that representation in a string. By default, the output is written to an instance of .

  Writes a formatted string followed by a line terminator to the trace listeners in the collection.

  A composite format string (see Remarks) that contains text intermixed with zero or more format items, which correspond to objects in the array. 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("DEBUG")
  System.Void

  This is equivalent to decrementing by one.

  Decreases the current by one.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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 object whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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("DEBUG")
  System.Void `` ``

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

  Use the parameter 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 object 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("DEBUG")
  System.Void `` ``

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

  Use the parameter 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("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the value is written to the trace listeners in the collection. An object whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the message is written 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("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the category name and value are written to the trace listeners in the collection. An object 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("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the category name and message are written 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("DEBUG")
  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 object whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Void ``

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

  This method calls the method of the trace listener.

  Writes a message followed by a line terminator 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("DEBUG")
  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 object whose name is sent to the . A category name used to organize the output.
- Method
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  System.Void `` `System.ParamArray`

  This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its text representation and embed that representation in a string.

  The params [.NET Framework] keyword in the syntax for this method implies that the object array can be a single value. The exception to this is the object. Explicit overloads take precedence, so an value of a single string will default to the overload.

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

  This method calls the method of the trace listener.

  Writes a formatted message followed by a line terminator to the trace listeners in the collection.

  A composite format string (see Remarks) that contains text intermixed with zero or more format items, which correspond to objects in the array. An object array that contains zero or more objects to format.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the value is written to the trace listeners in the collection. An object whose name is sent to the .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Diagnostics.Conditional("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the message is written 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("DEBUG")
  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.

  The conditional expression to evaluate. If the condition is true, the category name and value are written to the trace listeners in the collection. An object 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("DEBUG")
  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.