UdpAppender ClassApache log4net™ SDK Documentation
Sends logging events as connectionless UDP datagrams to a remote host or a multicast group using an UdpClient.
Inheritance Hierarchy

SystemObject
  log4net.AppenderAppenderSkeleton
    log4net.AppenderUdpAppender
      log4net.AppenderRemoteSyslogAppender

Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 2.0.6.0-.NET 4.0
Syntax

public class UdpAppender : AppenderSkeleton

The UdpAppender type exposes the following members.

Constructors

  NameDescription
Public methodUdpAppender
Initializes a new instance of the UdpAppender class.
Top
Properties

  NameDescription
Protected propertyClient
Gets or sets the underlying UdpClient.
Public propertyEncoding
Gets or sets Encoding used to write the packets.
Public propertyErrorHandler
Gets or sets the IErrorHandler for this appender.
(Inherited from AppenderSkeleton.)
Public propertyFilterHead
The filter chain.
(Inherited from AppenderSkeleton.)
Public propertyLayout
Gets or sets the ILayout for this appender.
(Inherited from AppenderSkeleton.)
Public propertyLocalPort
Gets or sets the TCP port number from which the underlying UdpClient will communicate.
Public propertyName
Gets or sets the name of this appender.
(Inherited from AppenderSkeleton.)
Public propertyRemoteAddress
Gets or sets the IP address of the remote host or multicast group to which the underlying UdpClient should sent the logging event.
Protected propertyRemoteEndPoint
Gets or sets the cached remote endpoint to which the logging events should be sent.
Public propertyRemotePort
Gets or sets the TCP port number of the remote host or multicast group to which the underlying UdpClient should sent the logging event.
Protected propertyRequiresLayout
This appender requires a log4net.Layout to be set.
(Overrides AppenderSkeletonRequiresLayout.)
Public propertyThreshold
Gets or sets the threshold Level of this appender.
(Inherited from AppenderSkeleton.)
Top
Methods

  NameDescription
Public methodActivateOptions
Initialize the appender based on the options set.
(Overrides AppenderSkeletonActivateOptions.)
Public methodAddFilter
Adds a filter to the end of the filter chain.
(Inherited from AppenderSkeleton.)
Protected methodAppend(LoggingEvent)
Append a bulk array of logging events.
(Inherited from AppenderSkeleton.)
Protected methodAppend(LoggingEvent)
This method is called by the DoAppend(LoggingEvent) method.
(Overrides AppenderSkeletonAppend(LoggingEvent).)
Public methodClearFilters
Clears the filter list for this appender.
(Inherited from AppenderSkeleton.)
Public methodClose
Closes the appender and release resources.
(Inherited from AppenderSkeleton.)
Public methodDoAppend(LoggingEvent)
Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent)] method.
(Inherited from AppenderSkeleton.)
Public methodDoAppend(LoggingEvent)
Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent[])] method.
(Inherited from AppenderSkeleton.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFilterEvent
Test if the logging event should we output by this appender
(Inherited from AppenderSkeleton.)
Protected methodFinalize
Finalizes this appender by calling the implementation's Close method.
(Inherited from AppenderSkeleton.)
Public methodFlush
Flushes any buffered log data.
(Inherited from AppenderSkeleton.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodInitializeClientConnection
Initializes the underlying UdpClient connection.
Protected methodIsAsSevereAsThreshold
Checks if the message level is below this appender's threshold.
(Inherited from AppenderSkeleton.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnClose
Closes the UDP connection and releases all resources associated with this UdpAppender instance.
(Overrides AppenderSkeletonOnClose.)
Protected methodPreAppendCheck
Called before [M:Append(LoggingEvent)] as a precondition.
(Inherited from AppenderSkeleton.)
Protected methodRenderLoggingEvent(LoggingEvent)
Renders the LoggingEvent to a string.
(Inherited from AppenderSkeleton.)
Protected methodRenderLoggingEvent(TextWriter, LoggingEvent)
Renders the LoggingEvent to a string.
(Inherited from AppenderSkeleton.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Remarks

UDP guarantees neither that messages arrive, nor that they arrive in the correct order.

To view the logging results, a custom application can be developed that listens for logging events.

When decoding events send via this appender remember to use the same encoding to decode the events as was used to send the events. See the Encoding property to specify the encoding to use.

Examples

This example shows how to log receive logging events that are sent on IP address 244.0.0.1 and port 8080 to the console. The event is encoded in the packet as a unicode string and it is decoded as such.
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
UdpClient udpClient;
byte[] buffer;
string loggingEvent;

try 
{
    udpClient = new UdpClient(8080);

    while(true) 
    {
        buffer = udpClient.Receive(ref remoteEndPoint);
        loggingEvent = System.Text.Encoding.Unicode.GetString(buffer);
        Console.WriteLine(loggingEvent);
    }
} 
catch(Exception e) 
{
    Console.WriteLine(e.ToString());
}

An example configuration section to log information using this appender to the IP 224.0.0.1 on port 8080:

<appender name="UdpAppender" type="log4net.Appender.UdpAppender"><remoteAddress value="224.0.0.1" /><remotePort value="8080" /><layout type="log4net.Layout.PatternLayout" value="%-5level %logger [%ndc] - %message%newline" /></appender>
See Also

Reference