ScopeContext - Allow child task to propagate context properties to parent
Author: snakefootCreated Oct 28, 2021Updated Jun 25, 2026
Labelsfeatureup-for-grabs
Maybe something like this, where it possible to do this:
using var propertyCollector = ScopeContext.PushPropertyCollector();
ScopeContext.CollectProperty("parentproperty", "value");
ScopeContext.CollectProperty("sharedproperty", "value");
await ChildTaskAsync(); // Pushes properties to ScopeContext
Logger.Info("Includes properties from child task");
async void ChildTaskAsync()
{
ScopeContext.CollectProperty("childproperty", "value");
await Task.Delay(1);
ScopeContext.CollectProperty("sharedproperty", "value2"); // overwrites
}The properties included in the property-collector should be accessible when using ${scopeproperty} or IncludeScopeProperties = true.
Guess one could manually inject a ConcurrentDictionary as scope-property at the parent-task-scopecontext, and then child-tasks can resolve that scope-property and insert their own propagating-properties into the ConcurrentDictionary. Thus parent-task-scopecontext will see that the scope-property with ConcurrentDictionary has the propagating-values from the child-tasks.
Source: NLog/NLog