public static string GetDebugInfo(this IInstanceIdentifiable instance) { if (instance == null) { return("(NULL)"); } return($"(id: {instance.InstanceId.ToString("N").Substring(0, 8)} from thread: {instance.CreatedThreadId})"); }
private static void SetCallContextObject(string key, IInstanceIdentifiable value) { #if DEBUG_SCOPES // manage the 'context' that contains the scope (null, "http" or "call") // only for scopes of course! if (key == ScopeItemKey) { // first, null-register the existing value var ambientKey = CallContext.LogicalGetData(ScopeItemKey).AsGuid(); object o = null; lock (StaticCallContextObjectsLock) { if (ambientKey != default(Guid)) { StaticCallContextObjects.TryGetValue(ambientKey, out o); } } var ambientScope = o as IScope; if (ambientScope != null) { RegisterContext(ambientScope, null); } // then register the new value var scope = value as IScope; if (scope != null) { RegisterContext(scope, "call"); } } #endif if (value == null) { var objectKey = CallContext.LogicalGetData(key).AsGuid(); CallContext.FreeNamedDataSlot(key); if (objectKey == default) { return; } lock (StaticCallContextObjectsLock) { #if DEBUG_SCOPES Current.Logger.Debug <ScopeProvider>("Remove Object " + objectKey.ToString("N").Substring(0, 8)); //Current.Logger.Debug<ScopeProvider>("At:\r\n" + Head(Environment.StackTrace, 24)); #endif StaticCallContextObjects.Remove(objectKey); } } else { // note - we are *not* detecting an already-existing value // because our code in this class *always* sets to null before // setting to a real value var objectKey = value.InstanceId; lock (StaticCallContextObjectsLock) { #if DEBUG_SCOPES Current.Logger.Debug <ScopeProvider>("AddObject " + objectKey.ToString("N").Substring(0, 8)); //Current.Logger.Debug<ScopeProvider>("At:\r\n" + Head(Environment.StackTrace, 24)); #endif StaticCallContextObjects.Add(objectKey, value); } CallContext.LogicalSetData(key, objectKey); } }