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)
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.
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>