UdpAppender Class | Apache log4net™ SDK Documentation

Sends logging events as connectionless UDP datagrams to a remote host or a multicast group using an UdpClient.
Inheritance Hierarchy

System
Object
log4net.Appender
AppenderSkeleton
log4net.Appender
UdpAppender
log4net.Appender
RemoteSyslogAppender

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

C#
VB
C++
F#
Copy

    public class UdpAppender : AppenderSkeleton

    Public Class UdpAppender
    	Inherits AppenderSkeleton

    public ref class UdpAppender : public AppenderSkeleton

    type UdpAppender =
        class
            inherit AppenderSkeleton
        end

The UdpAppender type exposes the following members.

Constructors

| Name | Description
--- | --- | ---
| UdpAppender | Initializes a new instance of the UdpAppender class.

Top
Properties

| Name | Description
--- | --- | ---
| Client | Gets or sets the underlying UdpClient.
| Encoding | Gets or sets Encoding used to write the packets.
| ErrorHandler | Gets or sets the IErrorHandler for this appender. (Inherited from AppenderSkeleton.)
| FilterHead | The filter chain. (Inherited from AppenderSkeleton.)
| Layout | Gets or sets the ILayout for this appender. (Inherited from AppenderSkeleton.)
| LocalPort | Gets or sets the TCP port number from which the underlying UdpClient will communicate.
| Name | Gets or sets the name of this appender. (Inherited from AppenderSkeleton.)
| RemoteAddress | Gets or sets the IP address of the remote host or multicast group to which the underlying UdpClient should sent the logging event.
| RemoteEndPoint | Gets or sets the cached remote endpoint to which the logging events should be sent.
| RemotePort | Gets or sets the TCP port number of the remote host or multicast group to which the underlying UdpClient should sent the logging event.
| RequiresLayout | This appender requires a log4net.Layout to be set. (Overrides AppenderSkeleton RequiresLayout.)
| Threshold | Gets or sets the threshold Level of this appender. (Inherited from AppenderSkeleton.)

Top
Methods

| Name | Description
--- | --- | ---
| ActivateOptions | Initialize the appender based on the options set. (Overrides AppenderSkeleton ActivateOptions .)
| AddFilter | Adds a filter to the end of the filter chain. (Inherited from AppenderSkeleton.)
| Append( LoggingEvent ) | Append a bulk array of logging events. (Inherited from AppenderSkeleton.)
| Append(LoggingEvent) | This method is called by the DoAppend(LoggingEvent) method. (Overrides AppenderSkeleton Append(LoggingEvent).)
| ClearFilters | Clears the filter list for this appender. (Inherited from AppenderSkeleton.)
| Close | Closes the appender and release resources. (Inherited from AppenderSkeleton.)
| DoAppend(LoggingEvent) | Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent)] method. (Inherited from AppenderSkeleton.)
| DoAppend( LoggingEvent ) | Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent[])] method. (Inherited from AppenderSkeleton.)
| Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
| FilterEvent | Test if the logging event should we output by this appender (Inherited from AppenderSkeleton.)
| Finalize | Finalizes this appender by calling the implementation's Close method. (Inherited from AppenderSkeleton.)
| Flush | Flushes any buffered log data. (Inherited from AppenderSkeleton.)
| GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.)
| GetType | Gets the Type of the current instance. (Inherited from Object.)
| InitializeClientConnection | Initializes the underlying UdpClient connection.
| IsAsSevereAsThreshold | Checks if the message level is below this appender's threshold. (Inherited from AppenderSkeleton.)
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.)
| OnClose | Closes the UDP connection and releases all resources associated with this UdpAppender instance. (Overrides AppenderSkeleton OnClose .)
| PreAppendCheck | Called before [M:Append(LoggingEvent)] as a precondition. (Inherited from AppenderSkeleton.)
| RenderLoggingEvent(LoggingEvent) | Renders the LoggingEvent to a string. (Inherited from AppenderSkeleton.)
| RenderLoggingEvent(TextWriter, LoggingEvent) | Renders the LoggingEvent to a string. (Inherited from AppenderSkeleton.)
| ToString | 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.
C#
VB
C++
F#
Copy

    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());
    }

    Dim remoteEndPoint as IPEndPoint
    Dim udpClient as UdpClient
    Dim buffer as Byte()
    Dim loggingEvent as String

    Try
        remoteEndPoint = new IPEndPoint(IPAddress.Any, 0)
        udpClient = new UdpClient(8080)

        While True
            buffer = udpClient.Receive(ByRef remoteEndPoint)
            loggingEvent = System.Text.Encoding.Unicode.GetString(buffer)
            Console.WriteLine(loggingEvent)
        Wend
    Catch e As Exception
        Console.WriteLine(e.ToString())
    End Try

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

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

Copy

    <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

log4net.Appender Namespace