Sends logging events as connectionless UDP datagrams to a remote host or a
multicast group using an UdpClient.
Inheritance Hierarchy
log4net.AppenderAppenderSkeleton
log4net.AppenderUdpAppender
log4net.AppenderRemoteSyslogAppender
Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 2.0.6.0-.NET 4.0
Syntax
The UdpAppender type exposes the following members.
Constructors
Name | Description | |
---|---|---|
UdpAppender |
Initializes a new instance of the UdpAppender class.
|
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 AppenderSkeletonRequiresLayout.) | |
Threshold |
Gets or sets the threshold Level of this appender.
(Inherited from AppenderSkeleton.) |
Methods
Name | Description | |
---|---|---|
ActivateOptions |
Initialize the appender based on the options set.
(Overrides AppenderSkeletonActivateOptions.) | |
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 AppenderSkeletonAppend(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 | (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 AppenderSkeletonOnClose.) | |
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 | (Inherited from Object.) |
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
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