Skip to content

Commit ea29f17

Browse files
committed
Add Peek() method to ThreadContextStack and LogicalThreadContextStack.
1 parent b2ef9f6 commit ea29f17

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

src/log4net/Util/LogicalThreadContextStack.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,35 @@ public IDisposable Push(string message)
198198
return new AutoPopStackFrame(contextStack, stack.Count - 1);
199199
}
200200

201-
#endregion Public Methods
202-
203-
#region Internal Methods
201+
/// <summary>
202+
/// Returns the top context from this stack.
203+
/// </summary>
204+
/// <returns>The message in the context from the top of this stack.</returns>
205+
/// <remarks>
206+
/// <para>
207+
/// Returns the top context from this stack. If this stack is empty then an
208+
/// empty string (not <see langword="null"/>) is returned.
209+
/// </para>
210+
/// </remarks>
211+
public string Peek()
212+
{
213+
Stack stack = m_stack;
214+
if (stack.Count > 0)
215+
{
216+
return ((StackFrame)stack.Peek()).Message;
217+
}
218+
return "";
219+
}
220+
221+
#endregion Public Methods
222+
223+
#region Internal Methods
204224

205-
/// <summary>
206-
/// Gets the current context information for this stack.
207-
/// </summary>
208-
/// <returns>The current context information.</returns>
209-
internal string GetFullMessage()
225+
/// <summary>
226+
/// Gets the current context information for this stack.
227+
/// </summary>
228+
/// <returns>The current context information.</returns>
229+
internal string GetFullMessage()
210230
{
211231
Stack stack = m_stack;
212232
if (stack.Count > 0)

src/log4net/Util/ThreadContextStack.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ public IDisposable Push(string message)
159159
return new AutoPopStackFrame(stack, stack.Count - 1);
160160
}
161161

162+
/// <summary>
163+
/// Returns the top context from this stack.
164+
/// </summary>
165+
/// <returns>The message in the context from the top of this stack.</returns>
166+
/// <remarks>
167+
/// <para>
168+
/// Returns the top context from this stack. If this stack is empty then an
169+
/// empty string (not <see langword="null"/>) is returned.
170+
/// </para>
171+
/// </remarks>
172+
public string Peek()
173+
{
174+
Stack stack = m_stack;
175+
if (stack.Count > 0)
176+
{
177+
return ((StackFrame)stack.Peek()).Message;
178+
}
179+
return "";
180+
}
181+
162182
#endregion Public Methods
163183

164184
#region Internal Methods

0 commit comments

Comments
 (0)