log4net SDK Reference

NDC.Push Method 

Pushes a new context message.

[Visual Basic]
Public Shared Function Push( _
   ByVal message As String _
) As IDisposable
[C#]
public static IDisposable Push(
   string message
);

Parameters

message
The new context message.

Return Value

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

Remarks

Note   

The NDC is deprecated and has been replaced by the Stacks. The current NDC implementation forwards to the ThreadContext.Stacks["NDC"].

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

Example

Simple example of using the Push method with the using keyword.

[C#]
using(log4net.NDC.Push("NDC_Message"))
{
    log.Warn("This should have an NDC message");
}

See Also

NDC Class | log4net Namespace