CorrelationManager 클래스

정의

논리 트랜잭션의 일부인 추적을 연관시킵니다.

public ref class CorrelationManager
public class CorrelationManager
type CorrelationManager = class
Public Class CorrelationManager
상속
CorrelationManager

예제

다음 코드 예제에서는 추적된 이벤트와 연결된 논리적 작업을 식별하여 클래스를 사용하는 CorrelationManager 방법을 보여 줍니다. 두 논리 작업이 시작됩니다. 하나는 주 스레드에, 다른 하나는 작업자 스레드에서 시작됩니다. 오류 이벤트는 두 논리 작업 모두에 기록됩니다.

#using <System.dll>

using namespace System;
using namespace System::Collections::Generic;
using namespace System::Text;
using namespace System::Diagnostics;
using namespace System::Threading;

void ThreadProc()
{
    TraceSource^ ts = gcnew TraceSource("MyApp");
    int i = ts->Listeners->Add(gcnew ConsoleTraceListener());
    ts->Listeners[i]->TraceOutputOptions = TraceOptions::LogicalOperationStack;
    ts->Switch = gcnew SourceSwitch("MyAPP", "Verbose");
    // Add another logical operation.
    Trace::CorrelationManager->StartLogicalOperation("WorkerThread");

    ts->TraceEvent(TraceEventType::Error, 1, "Trace an error event.");
    Trace::CorrelationManager->StopLogicalOperation();
}

void main()
{
    TraceSource^ ts = gcnew TraceSource("MyApp");
    int i = ts->Listeners->Add(gcnew ConsoleTraceListener());
    ts->Listeners[i]->TraceOutputOptions = TraceOptions::LogicalOperationStack;
    ts->Switch = gcnew SourceSwitch("MyAPP", "Verbose");
    // Start the logical operation on the Main thread.
    Trace::CorrelationManager->StartLogicalOperation("MainThread");

    ts->TraceEvent(TraceEventType::Error, 1, "Trace an error event.");
    Thread^ t = gcnew Thread(gcnew ThreadStart(ThreadProc));
//   Start the worker thread.
    t->Start();
//  Give the worker thread a chance to execute.
    Thread::Sleep(1000);
    Trace::CorrelationManager->StopLogicalOperation();}



// 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace CorrlationManager
{
    class Program
    {
        //private static TraceSource ts;
        static void Main(string[] args)
        {
            TraceSource ts = new TraceSource("MyApp");
            int i = 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.");
            Thread t = new Thread(new ThreadStart(ThreadProc));
            // Start the worker thread.
            t.Start();
            // Give the worker thread a chance to execute.
            Thread.Sleep(1000);
            Trace.CorrelationManager.StopLogicalOperation();
        }
        public static void ThreadProc()
        {
            TraceSource ts = new TraceSource("MyApp");
            int i = 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();
        }
    }
}
// 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
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
    
    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
End Class
' 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

설명

단일 논리 작업에서 생성된 추적은 다른 논리 작업과 추적을 구분하기 위해 작업 고유 ID로 태그를 지정할 수 있습니다. 예를 들어 상관 관계가 있는 추적을 ASP.NET 요청별로 그룹화하면 유용할 수 있습니다. 이 클래스는 CorrelationManager 스레드 바인딩된 컨텍스트에서 논리 작업 ID를 저장하고 스레드에서 생성된 각 추적 이벤트에 저장된 ID를 사용하여 자동으로 태그를 지정하는 데 사용되는 메서드를 제공합니다.

논리 연산을 중첩할 수도 있습니다. 이 속성은 LogicalOperationStack 중첩된 논리 작업 ID의 스택을 노출합니다. 메서드에 대한 각 호출은 StartLogicalOperation 새 논리 작업 ID를 스택에 푸시합니다. 메서드에 대한 각 호출은 StopLogicalOperation 스택에서 논리 작업 ID를 팝합니다.

참고

논리 작업 ID는 개체이므로 논리적 작업 ID에 형식을 사용할 수 있습니다.

속성

ActivityId

전역 작업에 대한 ID를 가져오거나 설정합니다.

LogicalOperationStack

호출 컨텍스트에서 논리 작업 스택을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
StartLogicalOperation()

스레드에서 논리 작업을 시작합니다.

StartLogicalOperation(Object)

스레드에서 지정된 ID를 사용하여 논리 작업을 시작합니다.

StopLogicalOperation()

현재 논리 작업을 중지합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상