Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:08:19+00:00 2026-05-26T09:08:19+00:00

In MSDN I found an article on how to assign some traces to a

  • 0

In MSDN I found an article on how to assign some traces to a specific action. This comes in handy when examining a trace log in the Microsoft Service Trace Viewer, because you can click on an activity to see what’s going on with that specific action.

Here’s the code example from the article, how you assign some trace event to an action:

Guid traceID = Guid.NewGuid();
ts.TraceTransfer(0, "transfer", traceID);
Trace.CorrelationManager.ActivityId = traceID; // Trace is static
ts.TraceEvent(TraceEventType.Start, 0, "Add request");

The problem is: CorrelationManager is static and thus affects the whole application. What do you do in a multi-threaded application?
Unfortunately I found no way to accomplish multiple parallel activities.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:08:19+00:00Added an answer on May 26, 2026 at 9:08 am

    Trace is static. However, CorrelationManager stores ActivityId and LogicalOperationStack in a form of thread local storage. CorrelationManager uses CallContext.LogicalSetData to store values in the CallContext.

    This means that each thread can have its own ActivityId and LogicalOperationStack.

    In pseudocode the implementation for Trace.CorrelationManager and CorrelationManager.ActivityId looks something like this:

    public static class Trace
    {
      private static correlationManager = null;
      public CorrelationManager CorrelationManager
      {
        get
        {
          if (correlationManager == null) correlationManager = new CorrelationManager();
          return correlationManager;
        }
      }
    }
    
    
    public class CorrelationManager
    {
      public Guid ActivityId
      {
        get
        {
          object id = CallContext.LogicalGetData("CorelationManager.ActivityId");
          if (id == null)
          {
            return Guid.Empty;
          }
          return (Guid) id;
        }
        set
        {
          CallContext.LogicalSetData("CorrelationManager.ActivityId", value);
        }
      }
    }
    

    As you can see, there is only one Trace “object” (since it is static) and there is only one CorrelationManager (since it is a property, a real object instance, on the Trace object). Per-thread instancing of context data (ActivityId and LogicalOperationStack) is achieved via the CallContext object.

    Data stored via CallContext.LogicalSetData also “flows” to downstream threads. So, if you set ActivityId at the beginning of a thread and that that thread subsequently spawns threads (which might spawn other threads), then all of those downstream threads will have the same ActivityId.

    You can see the source for Trace and CorrelationManager here (not sure what version of .Net this is from, but I suspect that it is pretty close to how Trace and CorrelationManager work today:

    Trace

    CorrelationManager

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While implementing Multithreaded Cache, i found this article on MSDN. http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx This is for
I've found this MSDN article that explains how to monitor processes and services with
I've just found some C++ code (at http://msdn.microsoft.com/en-us/library/k8336763(VS.71).aspx ), which uses a technique I've
I found this article regarding Linq-to-SQL and SQL Server connection pooling: MSDN Blog From
According to the MSDN article found at http://msdn.microsoft.com/en-us/library/wyk4d9cy.aspx the floating-point value .1 has no
EDIT: I found an article that lists exactly what I needed: http://msdn.microsoft.com/en-us/library/ms646309(v=vs.85).aspx Thanks for
I was digging around in MSDN and found this article which had one interesting
I found this article ( http://blogs.msdn.com/b/narend/archive/2006/10/13/how-to-extend-linking-and-workitem-ui-with-custom-link-types.aspx ) about link extensibility in TFS 2005. I'm
I found a topic on MSDN that talks that yes, this is possible. I
I've asked this question over on the MSDN forums also and haven't found a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.