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

OnlineSystem Object
  log4net.Appender AppenderSkeleton
    log4net.Appender UdpAppender
      log4net.Appender RemoteSyslogAppender

Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 1.2.15.0 (1.2.15.0)
Syntax

public class UdpAppender : AppenderSkeleton
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());
}
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

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