Class RemoteSyslogAppender
Logs events to a remote syslog daemon.
public class RemoteSyslogAppender : UdpAppender, IBulkAppender, IAppender, IOptionHandler, IFlushable
- Inheritance
-
RemoteSyslogAppender
- Implements
- Inherited Members
Remarks
The BSD syslog protocol is used to remotely log to a syslog daemon. The syslogd listens for messages on UDP port 514.
The syslog UDP protocol is not authenticated. Most syslog daemons do not accept remote log messages because of the security implications. You may be able to use the LocalSyslogAppender to talk to a local syslog service.
There is an RFC 3164 that claims to document the BSD Syslog Protocol. This RFC can be seen here: http://www.faqs.org/rfcs/rfc3164.html. This appender generates what the RFC calls an "Original Device Message", i.e. does not include the TIMESTAMP or HOSTNAME fields. By observation this format of message will be accepted by all current syslog daemon implementations. The daemon will attach the current time and the source hostname or IP address to any messages received.
Syslog messages must have a facility and a severity. The severity is derived from the Level of the logging event. The facility must be chosen from the set of defined syslog RemoteSyslogAppender.SyslogFacility values. The facilities list is predefined and cannot be extended.
An identifier is specified with each log message. This can be specified by setting the Identity property. The identity (also known as the tag) must not contain white space. The default value for the identity is the application name (from Domain).
Constructors
RemoteSyslogAppender()
Initializes a new instance of the RemoteSyslogAppender class.
public RemoteSyslogAppender()
Remarks
This instance of the RemoteSyslogAppender class is set up to write to a remote syslog daemon.
Properties
EnqueueTimeoutMillis
How long a logging call waits for room in a full queue. Defaults to 5000, 0 never waits.
public int EnqueueTimeoutMillis { get; set; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value specified is negative.
Facility
Syslog facility
public RemoteSyslogAppender.SyslogFacility Facility { get; set; }
Property Value
Remarks
Set to one of the RemoteSyslogAppender.SyslogFacility values. The list of facilities is predefined and cannot be extended. The default value is User.
Identity
Message identity
public PatternLayout? Identity { get; set; }
Property Value
Remarks
An identifier is specified with each log message. This can be specified by setting the Identity property. The identity (also known as the tag) must not contain white space. The default value for the identity is the application name (from Domain).
NewLineHandling
NewLine handling
public SyslogNewLineHandling NewLineHandling { get; set; }
Property Value
Remarks
The default value is Escape.
SendQueueSize
How many datagrams may wait to be sent. Defaults to 500.
public int SendQueueSize { get; set; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value specified is not positive.
Methods
ActivateOptions()
Initialize the options for this appender
public override void ActivateOptions()
Remarks
Initialize the level to syslog severity mappings set on this appender.
AddMapping(LevelSeverity)
Add a mapping of level to severity
public void AddMapping(RemoteSyslogAppender.LevelSeverity mapping)
Parameters
mappingRemoteSyslogAppender.LevelSeverityThe mapping to add
Remarks
Add a RemoteSyslogAppender.LevelSeverity mapping to this appender.
Append(LoggingEvent)
Writes the event to a remote syslog daemon.
protected override void Append(LoggingEvent loggingEvent)
Parameters
loggingEventLoggingEventThe event to log.
Remarks
This method is called by the DoAppend(LoggingEvent) method.
The format of the output will depend on the appender's layout.
AppendMessage(string, ref int, StringBuilder)
Appends the rendered message to the buffer
[SuppressMessage("Design", "CA1045:Do not pass types by reference")]
protected virtual void AppendMessage(string message, ref int characterIndex, StringBuilder builder)
Parameters
messagestringrendered message
characterIndexintindex of the current character in the message
builderStringBuilderbuffer
CreateUdpConnection()
Gets or sets the delegate used to create instances of log4net.Appender.Internal.IUdpConnection.
protected virtual IUdpConnection CreateUdpConnection()
Returns
- IUdpConnection
Flush(int)
Waits until everything queued so far has been sent.
public override bool Flush(int millisecondsTimeout)
Parameters
millisecondsTimeoutintThe maximum time to wait.
Returns
GeneratePriority(SyslogFacility, SyslogSeverity)
Generate a syslog priority.
public static int GeneratePriority(RemoteSyslogAppender.SyslogFacility facility, RemoteSyslogAppender.SyslogSeverity severity)
Parameters
facilityRemoteSyslogAppender.SyslogFacilityThe syslog facility.
severityRemoteSyslogAppender.SyslogSeverityThe syslog severity.
Returns
- int
A syslog priority.
Remarks
Generate a syslog priority.
GetSeverity(Level?)
Translates a log4net level to a syslog severity.
protected virtual RemoteSyslogAppender.SyslogSeverity GetSeverity(Level? level)
Parameters
levelLevelA log4net level.
Returns
- RemoteSyslogAppender.SyslogSeverity
A syslog severity.
InitializeClientConnection()
Initializes the underlying UdpClient connection.
protected override void InitializeClientConnection()
Remarks
The underlying UdpClient is initialized and binds to the port number from which you intend to communicate.
Exceptions are passed to the ErrorHandler.
OnClose()
Closes the UDP connection and releases all resources associated with this UdpAppender instance.
protected override void OnClose()
Remarks
Disables the underlying UdpClient and releases all managed and unmanaged resources associated with the UdpAppender.