Exemple #1
0
        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;
        }
Exemple #2
0
        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();
            }
        }