#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion
using System;
using System.Collections;
namespace log4net
{
///
/// Implementation of Mapped Diagnostic Contexts.
///
///
///
///
/// The MDC is deprecated and has been replaced by the .
/// The current MDC implementation forwards to the ThreadContext.Properties.
///
///
///
/// The MDC class is similar to the class except that it is
/// based on a map instead of a stack. It provides mapped
/// diagnostic contexts. A Mapped Diagnostic Context, or
/// MDC in short, is an instrument for distinguishing interleaved log
/// output from different sources. Log output is typically interleaved
/// when a server handles multiple clients near-simultaneously.
///
///
/// The MDC is managed on a per thread basis.
///
///
///
/// Nicko Cadell
/// Gert Driesen
/*[Obsolete("MDC has been replaced by ThreadContext.Properties")]*/
public sealed class MDC
{
#region Private Instance Constructors
///
/// Initializes a new instance of the class.
///
///
/// Uses a private access modifier to prevent instantiation of this class.
///
private MDC()
{
}
#endregion Private Instance Constructors
#region Public Static Methods
///
/// Gets the context value identified by the parameter.
///
/// The key to lookup in the MDC.
/// The string value held for the key, or a null reference if no corresponding value is found.
///
///
///
/// The MDC is deprecated and has been replaced by the .
/// The current MDC implementation forwards to the ThreadContext.Properties.
///
///
///
/// If the parameter does not look up to a
/// previously defined context then null will be returned.
///
///
/*[Obsolete("MDC has been replaced by ThreadContext.Properties")]*/
public static string Get(string key)
{
object obj = ThreadContext.Properties[key];
if (obj == null)
{
return null;
}
return obj.ToString();
}
///
/// Add an entry to the MDC
///
/// The key to store the value under.
/// The value to store.
///
///
///
/// The MDC is deprecated and has been replaced by the .
/// The current MDC implementation forwards to the ThreadContext.Properties.
///
///
///
/// Puts a context value (the parameter) as identified
/// with the parameter into the current thread's
/// context map.
///
///
/// If a value is already defined for the
/// specified then the value will be replaced. If the
/// is specified as null then the key value mapping will be removed.
///
///
/*[Obsolete("MDC has been replaced by ThreadContext.Properties")]*/
public static void Set(string key, string value)
{
ThreadContext.Properties[key] = value;
}
///
/// Removes the key value mapping for the key specified.
///
/// The key to remove.
///
///
///
/// The MDC is deprecated and has been replaced by the .
/// The current MDC implementation forwards to the ThreadContext.Properties.
///
///
///
/// Remove the specified entry from this thread's MDC
///
///
/*[Obsolete("MDC has been replaced by ThreadContext.Properties")]*/
public static void Remove(string key)
{
ThreadContext.Properties.Remove(key);
}
///
/// Clear all entries in the MDC
///
///
///
///
/// The MDC is deprecated and has been replaced by the .
/// The current MDC implementation forwards to the ThreadContext.Properties.
///
///
///
/// Remove all the entries from this thread's MDC
///
///
/*[Obsolete("MDC has been replaced by ThreadContext.Properties")]*/
public static void Clear()
{
ThreadContext.Properties.Clear();
}
#endregion Public Static Methods
}
}