Class RemotingAppender
Delivers logging events to a remote logging sink.
public class RemotingAppender : BufferingAppenderSkeleton, IBulkAppender, IAppender, IOptionHandler, IFlushable
- Inheritance
-
RemotingAppender
- Implements
- Inherited Members
Remarks
This Appender is designed to deliver events to a remote sink. That is any object that implements the RemotingAppender.IRemoteLoggingSink interface. It delivers the events using .NET remoting. The object to deliver events to is specified by setting the appenders Sink property.
The RemotingAppender buffers events before sending them. This allows it to make more efficient use of the remoting infrastructure.
Once the buffer is full the events are still not sent immediately. They are scheduled to be sent using a pool thread. The effect is that the send occurs asynchronously. This is very important for a number of non obvious reasons. The remoting infrastructure will flow thread local variables (stored in the System.Runtime.Remoting.Messaging.CallContext), if they are marked as System.Runtime.Remoting.Messaging.ILogicalThreadAffinative, across the remoting boundary. If the server is not contactable then the remoting infrastructure will clear the System.Runtime.Remoting.Messaging.ILogicalThreadAffinative objects from the System.Runtime.Remoting.Messaging.CallContext. To prevent a logging failure from having side effects on the calling application the remoting call must be made from a separate thread to the one used by the application. A ThreadPool thread is used for this. If no ThreadPool thread is available then the events will block in the thread pool manager until a thread is available.
Because the events are sent asynchronously using pool threads it is possible to close this appender before all the queued events have been sent. When closing the appender attempts to wait until all the queued events have been sent, but this will timeout after 30 seconds regardless.
If this appender is being closed because the ProcessExit event has fired it may not be possible to send all the queued events. During process exit the runtime limits the time that a ProcessExit event handler is allowed to run for. If the runtime terminates the threads before the queued events have been sent then they will be lost. To ensure that all events are sent the appender must be closed before the application exits. See Shutdown() for details on how to shutdown log4net programmatically.
Constructors
RemotingAppender()
Initializes a new instance of the RemotingAppender class.
public RemotingAppender()
Remarks
Default constructor.
Properties
Sink
Gets or sets the URL of the well-known object that will accept the logging events.
public string Sink { get; set; }
Property Value
- string
The well-known URL of the remote sink.
Remarks
The URL of the remoting sink that will accept logging events. The sink must implement the RemotingAppender.IRemoteLoggingSink interface.
Methods
ActivateOptions()
Initialize the appender based on the options set
public override void ActivateOptions()
Remarks
This is part of the IOptionHandler delayed object activation scheme. The ActivateOptions() method must be called on this object after the configuration properties have been set. Until ActivateOptions() is called this object is in an undefined state and must not be used.
If any of the configuration properties are modified then ActivateOptions() must be called again.
Flush(int)
Flushes any buffered log data.
public override bool Flush(int millisecondsTimeout)
Parameters
millisecondsTimeoutintThe maximum time to wait for logging events to be flushed.
Returns
- bool
Trueif all logging events were flushed successfully, elsefalse.
OnClose()
Override base class close.
protected override void OnClose()
Remarks
This method waits while there are queued work items. The events are sent asynchronously using ThreadPool work items. These items will be sent once a thread pool thread is available to send them, therefore it is possible to close the appender before all the queued events have been sent.
This method attempts to wait until all the queued events have been sent, but this method will timeout after 30 seconds regardless.
If the appender is being closed because the ProcessExit event has fired it may not be possible to send all the queued events. During process exit the runtime limits the time that a ProcessExit event handler is allowed to run for.
SendBuffer(LoggingEvent[])
Send the contents of the buffer to the remote sink.
protected override void SendBuffer(LoggingEvent[] events)
Parameters
eventsLoggingEvent[]The events to send.
Remarks
The events are not sent immediately. They are scheduled to be sent using a pool thread. The effect is that the send occurs asynchronously. This is very important for a number of non obvious reasons. The remoting infrastructure will flow thread local variables (stored in the System.Runtime.Remoting.Messaging.CallContext), if they are marked as System.Runtime.Remoting.Messaging.ILogicalThreadAffinative, across the remoting boundary. If the server is not contactable then the remoting infrastructure will clear the System.Runtime.Remoting.Messaging.ILogicalThreadAffinative objects from the System.Runtime.Remoting.Messaging.CallContext. To prevent a logging failure from having side effects on the calling application the remoting call must be made from a separate thread to the one used by the application. A ThreadPool thread is used for this. If no ThreadPool thread is available then the events will block in the thread pool manager until a thread is available.