Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/log4net/Util/LogicalThreadContextStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
namespace log4net.Util
{

/// <summary>
/// <summary>
/// Delegate type used for LogicalThreadContextStack's callbacks.
/// </summary>
#if NET_2_0 || MONO_2_0 || NETSTANDARD
#if NET_2_0 || MONO_2_0 || NETSTANDARD
public delegate void TwoArgAction<T1, T2>(T1 t1, T2 t2);
#else
#else
public delegate void TwoArgAction(string t1, LogicalThreadContextStack t2);
#endif
#endif

/// <summary>
/// <summary>
/// Implementation of Stack for the <see cref="log4net.LogicalThreadContext"/>
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -65,7 +65,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
/// </summary>
#if NET_2_0 || MONO_2_0 || NETSTANDARD
private TwoArgAction<string, LogicalThreadContextStack> m_registerNew;
#else
#else
private TwoArgAction m_registerNew;
#endif

Expand All @@ -83,7 +83,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
/// </remarks>
#if NET_2_0 || MONO_2_0 || NETSTANDARD
internal LogicalThreadContextStack(string propertyKey, TwoArgAction<string, LogicalThreadContextStack> registerNew)
#else
#else
internal LogicalThreadContextStack(string propertyKey, TwoArgAction registerNew)
#endif
{
Expand Down Expand Up @@ -198,6 +198,26 @@ public IDisposable Push(string message)
return new AutoPopStackFrame(contextStack, stack.Count - 1);
}

/// <summary>
/// Returns the top context from this stack.
/// </summary>
/// <returns>The message in the context from the top of this stack.</returns>
/// <remarks>
/// <para>
/// Returns the top context from this stack. If this stack is empty then an
/// empty string (not <see langword="null"/>) is returned.
/// </para>
/// </remarks>
public string Peek()
{
Stack stack = m_stack;
if (stack.Count > 0)
{
return ((StackFrame)stack.Peek()).Message;
}
return "";
}

#endregion Public Methods

#region Internal Methods
Expand Down
20 changes: 20 additions & 0 deletions src/log4net/Util/ThreadContextStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ public IDisposable Push(string message)
return new AutoPopStackFrame(stack, stack.Count - 1);
}

/// <summary>
/// Returns the top context from this stack.
/// </summary>
/// <returns>The message in the context from the top of this stack.</returns>
/// <remarks>
/// <para>
/// Returns the top context from this stack. If this stack is empty then an
/// empty string (not <see langword="null"/>) is returned.
/// </para>
/// </remarks>
public string Peek()
{
Stack stack = m_stack;
if (stack.Count > 0)
{
return ((StackFrame)stack.Peek()).Message;
}
return "";
}

#endregion Public Methods

#region Internal Methods
Expand Down