public void Add(string key, object value) { if (_contextAttributes.ContainsKey(key)) { return; } _contextAttributes[key] = value; if (ThreadLevelAttributes.ContainsKey(key)) { _replacedAttributes[key] = ThreadLevelAttributes[key]; } ThreadLevelAttributes[key] = value; }
private void Close() { foreach (var attribute in _contextAttributes) { if (ThreadLevelAttributes.ContainsKey(attribute.Key)) { ThreadLevelAttributes.Remove(attribute.Key); } } foreach (var attribute in _replacedAttributes) { ThreadLevelAttributes[attribute.Key] = attribute.Value; } OpenedContexts.Remove(this); if (OpenedContexts.Count == 0) { ThreadLevelAttributes.Clear(); } }