nicko       2005/02/13 19:45:01

  Modified:    src      NDC.cs
               src/Util ThreadContextStack.cs
  Log:
  Added support for all old methods in NDC - Depth, SetMaxDepth, CloneStack, 
Inherit
  
  Revision  Changes    Path
  1.13      +94 -15    logging-log4net/src/NDC.cs
  
  Index: NDC.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/NDC.cs,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- NDC.cs    17 Jan 2005 20:18:40 -0000      1.12
  +++ NDC.cs    14 Feb 2005 03:45:01 -0000      1.13
  @@ -25,10 +25,12 @@
        /// Implementation of Nested Diagnostic Contexts.
        /// </summary>
        /// <remarks>
  +     /// <note>
        /// <para>
        /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
        /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
        /// </para>
  +     /// </note>
        /// <para>
        /// A Nested Diagnostic Context, or NDC in short, is an instrument
        /// to distinguish interleaved log output from different sources. Log
  @@ -82,6 +84,12 @@
                /// </summary>
                /// <value>The current context depth.</value>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
                /// <para>
                /// The number of context values pushed onto the context stack.
                /// </para>
  @@ -91,10 +99,10 @@
                /// </para>
                /// </remarks>
                /// <seealso cref="SetMaxDepth"/>
  -             [Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
                public static int Depth
                {
  -                     get { throw new NotSupportedException("NDC has been 
replaced by ThreadContext.Stacks"); }
  +                     get { return ThreadContext.Stacks["NDC"].Count; }
                }
   
                #endregion Public Static Properties
  @@ -105,9 +113,17 @@
                /// Clears all the contextual information held on the current 
thread.
                /// </summary>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// Clears the stack of NDC data held on the current thread.
  +             /// </para>
                /// </remarks>
  -             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]*/
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
                public static void Clear() 
                {
                        ThreadContext.Stacks["NDC"].Clear();
  @@ -118,14 +134,22 @@
                /// </summary>
                /// <returns>A clone of the context info for this 
thread.</returns>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// The results of this method can be passed to the <see 
cref="Inherit"/> 
                /// method to allow child threads to inherit the context of 
their 
                /// parent thread.
  +             /// </para>
                /// </remarks>
  -             [Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
                public static Stack CloneStack() 
                {
  -                     throw new NotSupportedException("NDC has been replaced 
by ThreadContext.Stacks");
  +                     return ThreadContext.Stacks["NDC"].InternalStack;
                }
   
                /// <summary>
  @@ -133,6 +157,13 @@
                /// </summary>
                /// <param name="stack">The context stack to inherit.</param>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// This thread will use the context information from the stack
                /// supplied. This can be used to initialize child threads with
                /// the same contextual information as their parent threads. 
These
  @@ -140,25 +171,34 @@
                /// are pushed onto the stack will not be visible to the other.
                /// Call <see cref="CloneStack"/> to obtain a stack to pass to
                /// this method.
  +             /// </para>
                /// </remarks>
  -             [Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]*/
                public static void Inherit(Stack stack) 
                {
  -                     throw new NotSupportedException("NDC has been replaced 
by ThreadContext.Stacks");
  +                     ThreadContext.Stacks["NDC"].InternalStack = stack;
                }
   
                /// <summary>
                /// Removes the top context from the stack.
                /// </summary>
  +             /// <returns>
  +             /// The message in the context that was removed from the top 
  +             /// of the stack.
  +             /// </returns>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// Remove the top context from the stack, and return
                /// it to the caller. If the stack is empty then an
                /// empty string (not <c>null</c>) is returned.
  +             /// </para>
                /// </remarks>
  -             /// <returns>
  -             /// The message in the context that was removed from the top 
  -             /// of the stack.
  -             /// </returns>
                /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
                public static string Pop() 
                {
  @@ -174,10 +214,18 @@
                /// the context stack.
                /// </returns>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// Pushes a new context onto the context stack. An <see 
cref="IDisposable"/>
                /// is returned that can be used to clean up the context stack. 
This
                /// can be easily combined with the <c>using</c> keyword to 
scope the
                /// context.
  +             /// </para>
                /// </remarks>
                /// <example>Simple example of using the <c>Push</c> method 
with the <c>using</c> keyword.
                /// <code lang="C#">
  @@ -198,9 +246,17 @@
                /// not required to call this method.
                /// </summary>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// This method is not implemented.
  +             /// </para>
                /// </remarks>
  -             [Obsolete("NDC has been replaced by ThreadContext.Stacks")]
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
                public static void Remove() 
                {
                }
  @@ -210,16 +266,39 @@
                /// </summary>
                /// <param name="maxDepth">The maximum depth of the 
stack</param>
                /// <remarks>
  +             /// <note>
  +             /// <para>
  +             /// The NDC is deprecated and has been replaced by the <see 
cref="ThreadContext.Stacks"/>.
  +             /// The current NDC implementation forwards to the 
<c>ThreadContext.Stacks["NDC"]</c>.
  +             /// </para>
  +             /// </note>
  +             /// <para>
                /// Forces the stack depth to be at most <paramref 
name="maxDepth"/>.
                /// This may truncate the head of the stack. This only affects 
the 
                /// stack in the current thread. Also it does not prevent it 
from
                /// growing, it only sets the maximum depth at the time of the
                /// call. This can be used to return to a known context depth.
  +             /// </para>
                /// </remarks>
  -             [Obsolete("NDC has been replaced by ThreadContext.Stacks", 
true)]
  -             static public void SetMaxDepth(int maxDepth) 
  +             /*[Obsolete("NDC has been replaced by ThreadContext.Stacks")]*/
  +             public static void SetMaxDepth(int maxDepth) 
                {
  -                     throw new NotSupportedException("NDC has been replaced 
by ThreadContext.Stacks");
  +                     if (maxDepth >= 0)
  +                     {
  +                             log4net.Util.ThreadContextStack stack = 
ThreadContext.Stacks["NDC"];
  +
  +                             if (maxDepth == 0)
  +                             {
  +                                     stack.Clear();
  +                             }
  +                             else
  +                             {
  +                                     while(stack.Count > maxDepth)
  +                                     {
  +                                             stack.Pop();
  +                                     }
  +                             }
  +                     }
                }
   
                #endregion Public Static Methods
  
  
  
  1.6       +40 -1     logging-log4net/src/Util/ThreadContextStack.cs
  
  Index: ThreadContextStack.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/ThreadContextStack.cs,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ThreadContextStack.cs     7 Feb 2005 04:05:50 -0000       1.5
  +++ ThreadContextStack.cs     14 Feb 2005 03:45:01 -0000      1.6
  @@ -42,7 +42,7 @@
                /// <summary>
                /// The stack store.
                /// </summary>
  -             private readonly Stack m_stack = new Stack();
  +             private Stack m_stack = new Stack();
   
                #endregion Private Static Fields
   
  @@ -62,6 +62,28 @@
   
                #endregion Public Instance Constructors
   
  +             #region Public Properties
  +
  +             /// <summary>
  +             /// The number of messages in the stack
  +             /// </summary>
  +             /// <value>
  +             /// The current number of messages in the stack
  +             /// </value>
  +             /// <remarks>
  +             /// <para>
  +             /// The current number of messages in the stack. That is
  +             /// the number of times <see cref="Push"/> has been called
  +             /// minus the number of times <see cref="Pop"/> has been called.
  +             /// </para>
  +             /// </remarks>
  +             public int Count
  +             {
  +                     get { return m_stack.Count; }
  +             }
  +
  +             #endregion // Public Properties
  +
                #region Public Methods
   
                /// <summary>
  @@ -153,6 +175,23 @@
                        }
                        return null;
                }
  +
  +             /// <summary>
  +             /// Gets and sets the internal stack used by this <see 
cref="ThreadContextStack"/>
  +             /// </summary>
  +             /// <value>The internal storage stack</value>
  +             /// <remarks>
  +             /// <para>
  +             /// This property is provided only to support backward 
compatability 
  +             /// of the <see cref="NDC"/>. Tytpically the internal stack 
should not
  +             /// be modified.
  +             /// </para>
  +             /// </remarks>
  +             internal Stack InternalStack
  +             {
  +                     get { return m_stack; }
  +                     set { m_stack = value; }
  +             }
     
                #endregion Internal Methods
   
  
  
  

Reply via email to