In NLog there are two methods Set and SetScoped in MappedDiagnosticsLogicalContext Class
Does SetScoped method sets the scope to - per request and if yes - what would be the scope for Set method?
In NLog there are two methods Set and SetScoped in MappedDiagnosticsLogicalContext Class
Does SetScoped method sets the scope to - per request and if yes - what would be the scope for Set method?
The Set and the SetScoped are doing basically the same thing, except that the SetScoped returns a IDisposable which you could dispose for un-setting the value.
e.g. With Set
MappedDiagnosticsLogicalContext.Set("key1", "value1");
DoSomething();
MappedDiagnosticsLogicalContext.Remove("key1");
vs SetScoped
using(MappedDiagnosticsLogicalContext.SetScoped("key1", "value1"))
{
DoSomething();
}
The scope of the MappedDiagnosticsLogicalContext (MDLC) is the current thread and childs threads. So without remove/dispose it will be available on those threads. See also: MDLC docs