diff --git a/src/log4net/Util/LogicalThreadContextStack.cs b/src/log4net/Util/LogicalThreadContextStack.cs index 005b6c1f..dbad39a2 100644 --- a/src/log4net/Util/LogicalThreadContextStack.cs +++ b/src/log4net/Util/LogicalThreadContextStack.cs @@ -26,16 +26,16 @@ namespace log4net.Util { - /// + /// /// Delegate type used for LogicalThreadContextStack's callbacks. /// - #if NET_2_0 || MONO_2_0 || NETSTANDARD + #if NET_2_0 || MONO_2_0 || NETSTANDARD public delegate void TwoArgAction(T1 t1, T2 t2); - #else + #else public delegate void TwoArgAction(string t1, LogicalThreadContextStack t2); - #endif + #endif - /// + /// /// Implementation of Stack for the /// /// @@ -65,7 +65,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired /// #if NET_2_0 || MONO_2_0 || NETSTANDARD private TwoArgAction m_registerNew; - #else + #else private TwoArgAction m_registerNew; #endif @@ -83,7 +83,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired /// #if NET_2_0 || MONO_2_0 || NETSTANDARD internal LogicalThreadContextStack(string propertyKey, TwoArgAction registerNew) - #else + #else internal LogicalThreadContextStack(string propertyKey, TwoArgAction registerNew) #endif { @@ -198,6 +198,26 @@ public IDisposable Push(string message) return new AutoPopStackFrame(contextStack, stack.Count - 1); } + /// + /// Returns the top context from this stack. + /// + /// The message in the context from the top of this stack. + /// + /// + /// Returns the top context from this stack. If this stack is empty then an + /// empty string (not ) is returned. + /// + /// + public string Peek() + { + Stack stack = m_stack; + if (stack.Count > 0) + { + return ((StackFrame)stack.Peek()).Message; + } + return ""; + } + #endregion Public Methods #region Internal Methods diff --git a/src/log4net/Util/ThreadContextStack.cs b/src/log4net/Util/ThreadContextStack.cs index d723dca4..53d6fbae 100644 --- a/src/log4net/Util/ThreadContextStack.cs +++ b/src/log4net/Util/ThreadContextStack.cs @@ -159,6 +159,26 @@ public IDisposable Push(string message) return new AutoPopStackFrame(stack, stack.Count - 1); } + /// + /// Returns the top context from this stack. + /// + /// The message in the context from the top of this stack. + /// + /// + /// Returns the top context from this stack. If this stack is empty then an + /// empty string (not ) is returned. + /// + /// + public string Peek() + { + Stack stack = m_stack; + if (stack.Count > 0) + { + return ((StackFrame)stack.Peek()).Message; + } + return ""; + } + #endregion Public Methods #region Internal Methods