ThreadContextStack Push Method | Apache log4net™ SDK Documentation

Pushes a new context message into this stack.

Namespace: log4net.Util
Assembly: log4net (in log4net.dll) Version: 2.0.8.0-.NET 4.0
Syntax

C#
VB
C++
F#
Copy

    public IDisposable Push(
    	string message
    )

    Public Function Push (
    	message As String
    ) As IDisposable

    public:
    IDisposable^ Push(
    	String^ message
    )

    member Push :
            message : string -> IDisposable

#### Parameters

message
  Type: System
  String
  The new context message.

#### Return Value

Type: IDisposable
An IDisposable that can be used to clean up the context stack.
Remarks

Pushes a new context onto this stack. An IDisposable is returned that can be used to clean up this stack. This can be easily combined with the using keyword to scope the context.

Examples

Simple example of using the Push method with the using keyword.
C#
Copy

    using(log4net.ThreadContext.Stacks["NDC"].Push("Stack_Message"))
    {
        log.Warn("This should have an ThreadContext Stack message");
    }

See Also

#### Reference

ThreadContextStack Class
log4net.Util Namespace