You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/11/24 16:53:31 UTC
cvs commit: logging-log4net/src/Util ThreadContextStack.cs
nicko 2004/11/24 07:53:31
Modified: src NDC.cs
src/Util ThreadContextStack.cs
Log:
Reinstated Clear() method on ThreadContextStack and NDC
Revision Changes Path
1.10 +9 -10 logging-log4net/src/NDC.cs
Index: NDC.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/NDC.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- NDC.cs 22 Nov 2004 02:09:06 -0000 1.9
+++ NDC.cs 24 Nov 2004 15:53:29 -0000 1.10
@@ -27,7 +27,7 @@
/// <remarks>
/// <para>
/// The NDC is deprecated and has been replaced by the <see cref="ThreadContext.Stacks"/>.
- /// The current NDC implementation forwards to the ThreadContext.Stacks["NDC"].
+ /// The current NDC implementation forwards to the <c>ThreadContext.Stacks["NDC"]</c>.
/// </para>
/// <para>
/// A Nested Diagnostic Context, or NDC in short, is an instrument
@@ -47,7 +47,7 @@
/// </para>
/// </remarks>
/// <example>How to push a message into the context
- /// <code>
+ /// <code lang="C#">
/// using(NDC.Push("my context message"))
/// {
/// ... all log calls will have 'my context message' included ...
@@ -102,27 +102,26 @@
#region Public Static Methods
/// <summary>
- /// Clears all the contextual information held on the
- /// current thread.
+ /// Clears all the contextual information held on the current thread.
/// </summary>
/// <remarks>
- /// After calling this method the <see cref="Depth"/> will be <c>0</c>.
+ /// Clears the stack of NDC data held on the current thread.
/// </remarks>
- [Obsolete("NDC has been replaced by ThreadContext.Stacks", true)]
+ /*[Obsolete("NDC has been replaced by ThreadContext.Stacks", true)]*/
public static void Clear()
{
- throw new NotSupportedException("NDC has been replaced by ThreadContext.Stacks");
+ ThreadContext.Stacks["NDC"].Clear();
}
/// <summary>
/// Creates a clone of the stack of context information.
/// </summary>
+ /// <returns>A clone of the context info for this thread.</returns>
/// <remarks>
/// 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.
/// </remarks>
- /// <returns>A clone of the context info for this thread.</returns>
[Obsolete("NDC has been replaced by ThreadContext.Stacks", true)]
public static Stack CloneStack()
{
@@ -132,6 +131,7 @@
/// <summary>
/// Inherits the contextual information from another thread.
/// </summary>
+ /// <param name="stack">The context stack to inherit.</param>
/// <remarks>
/// This thread will use the context information from the stack
/// supplied. This can be used to initialize child threads with
@@ -141,7 +141,6 @@
/// Call <see cref="CloneStack"/> to obtain a stack to pass to
/// this method.
/// </remarks>
- /// <param name="stack">The context stack to inherit.</param>
[Obsolete("NDC has been replaced by ThreadContext.Stacks", true)]
public static void Inherit(Stack stack)
{
@@ -209,6 +208,7 @@
/// <summary>
/// Forces the stack depth to be at most <paramref name="maxDepth"/>.
/// </summary>
+ /// <param name="maxDepth">The maximum depth of the stack</param>
/// <remarks>
/// Forces the stack depth to be at most <paramref name="maxDepth"/>.
/// This may truncate the head of the stack. This only affects the
@@ -216,7 +216,6 @@
/// growing, it only sets the maximum depth at the time of the
/// call. This can be used to return to a known context depth.
/// </remarks>
- /// <param name="maxDepth">The maximum depth of the stack</param>
[Obsolete("NDC has been replaced by ThreadContext.Stacks", true)]
static public void SetMaxDepth(int maxDepth)
{
1.2 +19 -7 logging-log4net/src/Util/ThreadContextStack.cs
Index: ThreadContextStack.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/Util/ThreadContextStack.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ThreadContextStack.cs 9 Sep 2004 21:53:14 -0000 1.1
+++ ThreadContextStack.cs 24 Nov 2004 15:53:30 -0000 1.2
@@ -58,13 +58,25 @@
#region Public Methods
-// /// <summary>
-// /// Clears all the contextual information held in this stack.
-// /// </summary>
-// public void Clear()
-// {
-// m_stack.Clear();
-// }
+ /// <summary>
+ /// Clears all the contextual information held in this stack.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Clears all the contextual information held in this stack.
+ /// Only call this if you think that this tread is being reused after
+ /// a previous call execution which may not have completed correctly.
+ /// You do not need to use this method if you always guarantee to call
+ /// the <see cref="IDisposable.Dispose"/> method of the <see cref="IDisposable"/>
+ /// returned from <see cref="Push"/> even in exceptional circumstances,
+ /// for example by using the <c>using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))</c>
+ /// syntax.
+ /// </para>
+ /// </remarks>
+ public void Clear()
+ {
+ m_stack.Clear();
+ }
/// <summary>
/// Removes the top context from this stack.