2626namespace log4net . Util
2727{
2828
29- /// <summary>
29+ /// <summary>
3030 /// Delegate type used for LogicalThreadContextStack's callbacks.
3131 /// </summary>
32- #if NET_2_0 || MONO_2_0 || NETSTANDARD
32+ #if NET_2_0 || MONO_2_0 || NETSTANDARD
3333 public delegate void TwoArgAction < T1 , T2 > ( T1 t1 , T2 t2 ) ;
34- #else
34+ #else
3535 public delegate void TwoArgAction ( string t1 , LogicalThreadContextStack t2 ) ;
36- #endif
36+ #endif
3737
38- /// <summary>
38+ /// <summary>
3939 /// Implementation of Stack for the <see cref="log4net.LogicalThreadContext"/>
4040 /// </summary>
4141 /// <remarks>
@@ -65,7 +65,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
6565 /// </summary>
6666 #if NET_2_0 || MONO_2_0 || NETSTANDARD
6767 private TwoArgAction < string , LogicalThreadContextStack > m_registerNew ;
68- #else
68+ #else
6969 private TwoArgAction m_registerNew ;
7070 #endif
7171
@@ -83,7 +83,7 @@ public sealed class LogicalThreadContextStack : IFixingRequired
8383 /// </remarks>
8484 #if NET_2_0 || MONO_2_0 || NETSTANDARD
8585 internal LogicalThreadContextStack ( string propertyKey , TwoArgAction < string , LogicalThreadContextStack > registerNew )
86- #else
86+ #else
8787 internal LogicalThreadContextStack ( string propertyKey , TwoArgAction registerNew )
8888 #endif
8989 {
@@ -198,6 +198,26 @@ public IDisposable Push(string message)
198198 return new AutoPopStackFrame ( contextStack , stack . Count - 1 ) ;
199199 }
200200
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+
201221 #endregion Public Methods
202222
203223 #region Internal Methods
0 commit comments