Provides a set of properties and methods which help you track the execution of your code. This class can’t be inherited.

Cases

The next example utilizes Trace to signify the start and the conclusion of a program’s implementation. The case also uses the Trace.Indent and Trace.Unindent approaches to differentiate the tracing output. To get a more comprehensive example of the usage of Trace, visit How toAdd Trace Statements to Application Code.

Remarks

You may use the attributes and techniques from the Trace course to instrument release builds. Instrumentation permits you to track the health of your program running in real time settings. Tracing helps to isolate problems and repair them without even bothering a operating system.

This course provides methods to exhibit a Assert dialog box, and to create an assertion which will constantly Fail. This course provides write methods from these variants: Write, WriteLine, WriteIf, and WriteLineIf.

The BooleanSwitch and TraceSwitch courses provide means to control the tracing output. It is possible to alter the values of those switches without recompiling your program. For advice on using the setup file to set a change, visit the Switch class along with also the How toCreate, Initialize and Configure Trace Switches topic.

It is possible to personalize the tracing output’s goal with the addition of TraceListener cases to or removing cases in the Listeners collection. The Listeners set is shared with the Debug as well as also the Trace courses; including a trace listener to class adds the listener to the two. By default, trace output signal is emitted with the DefaultTraceListener course.

Notice

Including a trace listener to the Listeners collection may cause an exception to be thrown while tracing, in case a source utilized by the trace listener isn’t offered. The terms and the exception thrown are based on the trace listener and can’t be enumerated within this subject. It could be handy to put calls into the Trace approaches in attempt /grab cubes to detect and manage any exceptions out of trace listeners.

Notice

Should you include trace listeners to partially trusted code, then you’ll find a SecurityException exclusion, because adding trace listeners necessitates UnmanagedCode permission. To follow partially trusted code that’s running in a sandbox from Visual Studio, don’t include trace listeners. Instead, see the Trace and Debug messages from the Output window.

The Trace course provides properties for or set the degree of Indent, the IndentSize, also if to AutoFlush after every write.

To place up the AutoFlush and IndentSize to get Trace, it is possible to edit the configuration file that matches the title of your program. The configuration file Ought to Be formatted like the following example:

XMLCopy

The ConditionalAttribute feature is placed on the methods of Trace. Compilers that support ConditionalAttribute dismiss calls to those methods unless”TRACE” is described as a conditional compilation symbol. Refer to some compiler’s documentation to find out whether ConditionalAttribute is encouraged along with the syntax for specifying a conditional compilation symbol.

Notice

In Visual Studio jobs, by default, the”DEBUG” conditional compilation symbol is defined for debug builds, and also the”TRACE” emblem is defined for both debug and release builds. For information about how to disable this behaviour, see the Visual Studio documentation.

To specify the”TRACE” conditional compilation symbol in C#, insert the /d:TRACE alternative to the compiler command line when you compile your code using a command line, or insert #define TRACE towards the surface of your file. In Visual Basic, add the /d:TRACE=True alternative to the compiler command line or include #Const TRACE=True into the document.

ConditionalAttribute isn’t encouraged by the C++ compiler. To provide equal performance, you need to enclose calls to the techniques of Trace within an #if defined(TRACE)… #endif block, and insert the / / DTRACE alternative to the compiler command line or insert #define TRACE into the document.

Properties

Gets or sets whether Flush() ought to be known as about the Listeners after each write.

Gets the significance director for the thread with this hint.

Gets or sets the amount of spaces in an indent.

Gets the set of listeners that’s tracking the trace output.

Gets or sets a value indicating if the global lock ought to be used.

Methods

Checks for a condition; when the affliction is untrue , shows a message box which shows the call stack.

Checks for a condition; when the affliction is untrue , outputs a predetermined message also shows a message box which shows the call stack.

Checks for a condition; when the affliction is untrue , outputs two messages that are specified and displays a message box which shows the call stack.

Flushes the output buffer, then shuts the Listeners.

Determines if the given object is equivalent to the present item.

Emits the given error message.

Emits an error message, along with a detailed error message.

Flushes the output signal, and induces more data to be written to the Listeners.

Gets the Type of this present case.

Increases the Present IndentLevel by a single.

Creates a shallow copy of this present Object.

(Inherited from Object)Refresh()
Refreshes the trace configuration information.

ToString()
Returns a string that represents the current thing.

(Inherited from Object)TraceError(String)
Writes an error message to the trace listeners in the Listeners set with the given message.

TraceError(String, Object[])
Writes an error message to the trace listeners in the Listeners group with the given array of items and formatting info.

TraceInformation(String)
Writes an informational message to the trace listeners in the Listeners set with the given message.

TraceInformation(String, Object[])
Writes an informational message to the trace listeners in the Listeners group with the given array of items and formatting info.

TraceWarning(String)
Writes a warning message to the trace listeners in the Listeners collection with the given message.

TraceWarning(String, Object[])
Writes a warning message to the trace listeners in the Listeners group with the given array of items and formatting info.

Unindent()
Decreases the present IndentLevel by a single.

Write(Object)
Writes the value of this item’s ToString() method to the trace listeners in the Listeners collection.

Write(Object, String)
Writes a category name and the value of this item’s ToString() method to the trace listeners in the Listeners collection.

Write(String)
Writes a message to the trace listeners in the Listeners collection.

Write(String, String)
Writes a category name and a message to the trace listeners in the Listeners collection.

WriteIf(Boolean, Object)
Writes the value of this item’s ToString() method to the trace listeners in the Listeners collection if a condition is authentic .

WriteIf(Boolean, Object, String)
Writes a category name and the value of this item’s ToString() method to the trace listeners in the Listeners collection if a condition is authentic .

WriteIf(Boolean, String)
Writes a message to the trace listeners in the Listeners collection if a condition is authentic .

WriteIf(Boolean, String, String)
Writes a category name and message to the trace listeners in the Listeners collection if a condition is authentic .

WriteLine(Object)
Writes the value of this item’s ToString() method to the trace listeners in the Listeners collection.

WriteLine(Object, String)
Writes a category name and the value of this item’s ToString() method to the trace listeners in the Listeners collection.

WriteLine(String)
Writes a message to the trace listeners in the Listeners collection.

WriteLine(String, String)
Writes a category name and message to the trace listeners in the Listeners collection.

WriteLineIf(Boolean, Object)
Writes the value of this item’s ToString() method to the trace listeners in the Listeners collection if a condition is authentic .

WriteLineIf(Boolean, Object, String)
Writes a category name and the value of this item’s ToString() method to the trace listeners in the Listeners collection if a condition is authentic .

WriteLineIf(Boolean, String)
Writes a message to the trace listeners in the Listeners collection if a condition is authentic .

WriteLineIf(Boolean, String, String)
Writes a category name and message to the trace listeners in the Listeners collection if a condition is authentic .

Safety

SecurityPermission
For working with unmanaged code. Security actions: Demand. Associated enumeration: UnmanagedCode

Applies to

.NET Core
3.1 3.0 2.2 2.1 2.0 1.1 1.0
.NET Framework
4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1
.NET Standard
2.1 2.0
Xamarin.Android
7.1
Xamarin.iOS
10.8
Xamarin.Mac
3.0
Thread Safety

This kind is thread safe.