title: Tracking c#/.NET tasks flow
body: <p>I'm trying to find a way to keep a track on async tasks execution flow in a way that it would be easy to understand regarding task, what was the original flow that initiated it. I need it mostly for logging, debugging and preserving a sort of stack trace for a specific execution flow.</p>
  
  <p>For example: If I have a server with many clients from multiple IPs and the server needs to execute a work flow for each client that involves many async actions thus involves many different tasks per execution flow; logging such a flow is difficult especially when using <code>async/await</code> mechanism.</p>
  
  <p>I haven't figured out a way to wrap the tasks in a way that for each task that is executed I would know the initial flow description when logging. For example if I start a new flow of tasks for an action with description - "Taking care of 10.0.3.4 client" I want to be able to add this description for each log item coming out from this flow in any task that created from it.</p>
  
  <p>When using threads only, its easy because you have thread static variables. with tasks its impossible...
  I even tried to create my own task scheduler that will wrap out any task that uses it (even when using <code>async/await</code> methods) but got into a dead end because the task scheduler base sometimes uses new threads (even though there wasn't any implicit request to use a new thread)- the method <code>TryExecuteTaskInline</code> can sometimes run in a new thread.</p>
  
  <p>Any idea or suggestion of how can I achieve that?</p>