Provides a set of properties and methods which enable software to follow the implementation of code and connect trace messages using their origin.

Public course TraceSource
Inheritance

Cases

This code example demonstrates the usage of this TraceSource course to forward hints to listeners. The example also shows filter and switch use.

// The following configuration file may be used for this sample.
// When using a setup document #define ConfigFile.
//
//
//
//
//
//
//
//
#define TRACE
//#define ConfigFile

using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Security.Permissions;

namespace Testing
Remarks

The TraceSource course is used by software to create traces which may be connected with the program. TraceSource provides tracing techniques that enable you to readily follow events, trace information, and problem informational traces. Trace output signal from TraceSource may be controlled by configuration file preferences. The configuration file is found in the folder using the program executable and contains the title of this program with the .config file name expansion included. By way of instance, the title of this setup document for TraceSourceSample.exe is TraceSourceSample.exe.config. The configuration file may be used to ascertain where the trace data is to be routed and what amounts of action should be tracked. The next example shows the contents of a sample program configuration file.

XMLCopy

<origin title =”TraceTest” switchName=”SourceSwitch”
switchType=”System.Diagnostics.SourceSwitch” p

<include name=”console”
form =”System.Diagnostics.ConsoleTraceListener”
initializeData=”false”/>

The TraceSource course is recognized by the title of a source, typically the title of this program. The trace messages coming from a specific component could be initiated by a specific trace supply, permitting all messages coming from this part to be readily identified.

TraceSource defines tracking methods but doesn’t really supply any particular mechanism for creating and saving data that is tracing. The tracing information is made by trace listeners, which can be plug-ins which may be loaded by follow resources.

Notice

You shouldn’t telephone the tracing methods through finalization. Doing this could lead to an ObjectDisposedException being chucked.

It is possible to personalize the tracing output’s goal by removing or adding TraceListener cases to or by the collection stored at the TraceSource.Listeners real estate. By default, trace output is made with an instance of this DefaultTraceListener class. The previous configuration file example illustrates eliminating the DefaultTraceListener and including a ConsoleTraceListener to create the trace output for the trace supply. To Learn More, visit and .

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 TraceSource approaches in attempt /grab cubes to detect and manage any exceptions out of trace listeners.

The SourceSwitch course provides the method to control the tracing output. The previous configuration file example shows how it is possible to switch off tracing from a hint source and command the amount where tracing happens. It is possible to alter the value of this source button without recompiling your program. For advice on using the setup file to set a change, visit Switch and How toCreate, Initialize and Configure Trace Switches.

Notice

If you alter a configuration file while an application is currently executing, the program has to be stopped and restarted or the Refresh method should be called before the new settings take effect.

The TraceEventType enumeration can be used to specify the function type of the message. Trace filters utilize the TraceEventType to establish whether a trace listener should create the message.

The trace listeners may have another layer of filtering via a filter. When a trace listener has an associated filter, then the listener calls for the ShouldTrace system on such filter to ascertain whether or not to create the trace details.

The trace listeners utilize the values of this Trace class possessions Indent, IndentSize, and AutoFlush to format trace output. It’s possible to use configuration file features to place the Indent, IndentSize, and AutoFlush properties. The next example sets the AutoFlush land to untrue as well as also the IndentSize land to 3.

XMLCopy

Constructors

Initializes a new instance of this TraceSource course, with the specified title for the origin.

Initializes a new instance of this TraceSource course, with the specified title for the origin along with the default source amount where tracing is to happen.

Properties

Gets the custom switch features defined in the application configuration file.

Gets the set of trace listeners to the trace supply.

Gets the title of the trace supply.

Gets or sets the source change worth.

Methods

Closes all of the trace listeners in the trace listener collection.

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

Flushes all of the trace listeners in the trace listener collection.

(Inherited from Object)GetSupportedAttributes()
Gets the custom attributes supported by the trace supply.

GetType()
Gets the Type of this present case.

(Inherited from Object)MemberwiseClone()
Creates a shallow copy of this present Object.

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

(Inherited from Object)TraceData(TraceEventType, Int32, Object)
Writes trace information to the trace listeners in the Listeners group with the specified event type, event identifier, and follow information.

TraceData(TraceEventType, Int32, Object[])
Writes trace information to the trace listeners in the Listeners group with the given event type, event identifier, and follow information array.

TraceEvent(TraceEventType, Int32)
Writes a trace event message to the trace listeners in the Listeners group with the given event type and event identifier.

TraceEvent(TraceEventType, Int32, String)
Writes a trace event message to the trace listeners in the Listeners group with the given event type, event identifier, and message.

TraceEvent(TraceEventType, Int32, String, Object[])
Writes a follow up event to the trace listeners in the Listeners group with the given event type, event identifier, and debate range and format.

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 collection with the specified object range and formatting info.

TraceTransfer(Int32, String, Guid)
Writes a trace transfer message to the trace listeners in the Listeners collection with the specified numerical identifier, message, and relevant action identifier.

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