Correlates traces that are part of a logical transaction.
Assembly: System (in System.dll)
Traces generated from a single logical operation can be tagged with an operation-unique identity, in order to distinguish them from traces from a different logical operation. For example, it may be useful to group correlated traces by ASP.NET request. 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.
Logical operations can also be nested. The LogicalOperationStack property exposes the stack of nested logical operation identities. Each call to the StartLogicalOperation method pushes a new logical operation identity onto the stack. Each call to the StopLogicalOperation method pops a logical operation identity off the stack.
Logical operation identities are objects, allowing the use of a type for a logical operation identity.
The following code example demonstrates the use of the class by identifying the logical operation associated with a traced event. Two logical operations are started, one in the main thread and the other in a worker thread. An error event is logged in both logical operations.
Imports System Imports System.Collections.Generic Imports System.Text Imports System.Diagnostics Imports System.Threading Class Program 'private static TraceSource ts; Shared Sub Main(ByVal args() As String) Dim ts As New TraceSource("MyApp") Dim i As Integer = ts.Listeners.Add(New ConsoleTraceListener()) ts.Listeners(i).TraceOutputOptions = TraceOptions.LogicalOperationStack ts.Switch = New SourceSwitch("MyAPP", "Verbose") ' Start the logical operation on the Main thread. Trace.CorrelationManager.StartLogicalOperation("MainThread") ts.TraceEvent(TraceEventType.Error, 1, "Trace an error event.") Dim t As New Thread(New ThreadStart(AddressOf ThreadProc)) ' Start the worker thread. t.Start() ' Give the worker thread a chance to execute. Thread.Sleep(1000) Trace.CorrelationManager.StopLogicalOperation() End Sub 'Main Public Shared Sub ThreadProc() Dim ts As New TraceSource("MyApp") Dim i As Integer = ts.Listeners.Add(New ConsoleTraceListener()) ts.Listeners(i).TraceOutputOptions = TraceOptions.LogicalOperationStack ts.Switch = New SourceSwitch("MyAPP", "Verbose") ' Add another logical operation. Trace.CorrelationManager.StartLogicalOperation("WorkerThread") ts.TraceEvent(TraceEventType.Error, 1, "Trace an error event.") Trace.CorrelationManager.StopLogicalOperation() End Sub 'ThreadProc End Class 'Program ' This sample generates the following output: 'MyApp Error: 1 : Trace an error event. ' LogicalOperationStack=MainThread 'MyApp Error: 1 : Trace an error event. ' LogicalOperationStack=WorkerThread, MainThread
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.