Index: src/log4net/Appender/RemoteSyslogAppender.cs
===================================================================
--- src/log4net/Appender/RemoteSyslogAppender.cs (revision 1555712)
+++ src/log4net/Appender/RemoteSyslogAppender.cs (working copy)
@@ -18,7 +18,7 @@
#endregion
using System;
-
+using System.Net.Sockets;
using log4net.Core;
using log4net.Appender;
using log4net.Util;
@@ -312,6 +312,16 @@
set { m_facility = value; }
}
+ ///
+ /// Use String RFC3164 for sending the messages, split messages by new
+ /// line and don't send non ascii characters
+ ///
+ public Boolean StrictRFC3164
+ {
+ get { return m_strictRFC3164; }
+ set { this.m_strictRFC3164 = value; }
+ }
+
#endregion Public Instance Properties
///
@@ -383,33 +393,45 @@
// Write identity
builder.Append(identity);
builder.Append(": ");
-
- for (; i < message.Length; i++)
+ if (m_strictRFC3164)
{
- c = message[i];
+ for (; i < message.Length; i++)
+ {
+ c = message[i];
- // Accept only visible ASCII characters and space. See RFC 3164 section 4.1.3
- if (((int)c >= 32) && ((int)c <= 126))
- {
- builder.Append(c);
- }
- // If character is newline, break and send the current line
- else if ((c == '\r') || (c == '\n'))
- {
- // Check the next character to handle \r\n or \n\r
- if ((message.Length > i + 1) && ((message[i + 1] == '\r') || (message[i + 1] == '\n')))
+ // Accept only visible ASCII characters and space. See RFC 3164 section 4.1.3
+ if (((int) c >= 32) && ((int) c <= 126))
{
+ builder.Append(c);
+ }
+ // If character is newline, break and send the current line
+ else if ((c == '\r') || (c == '\n'))
+ {
+ // Check the next character to handle \r\n or \n\r
+ if ((message.Length > i + 1) && ((message[i + 1] == '\r') || (message[i + 1] == '\n')))
+ {
+ i++;
+ }
i++;
+ break;
}
- i++;
- break;
}
}
+ else
+ {
+ builder.Append(message);
+ i = message.Length;
+ }
- // Grab as a byte array
+
+ //Grab as a byte array
buffer = this.Encoding.GetBytes(builder.ToString());
-
- this.Client.Send(buffer, buffer.Length, this.RemoteEndPoint);
+ Int32 offset = 0;
+ while (offset != buffer.Length)
+ {
+ offset += this.Client.SendTo(buffer, offset, buffer.Length - offset, SocketFlags.None,
+ this.RemoteEndPoint);
+ }
}
}
catch (Exception e)
@@ -539,6 +561,11 @@
///
private PatternLayout m_identity;
+ ///
+ /// Follow RFC3164 RFC, don't send non ascii chars and split lines by cr/lf
+ ///
+ private Boolean m_strictRFC3164 = true;
+
///
/// Mapping from level object to syslog severity
///
@@ -554,6 +581,8 @@
///
private const int c_renderBufferMaxCapacity = 1024;
+
+
#endregion Private Instances Fields
#region LevelSeverity LevelMapping Entry
Index: src/log4net/Appender/UdpAppender.cs
===================================================================
--- src/log4net/Appender/UdpAppender.cs (revision 1555712)
+++ src/log4net/Appender/UdpAppender.cs (working copy)
@@ -302,7 +302,7 @@
/// returned from if you require access beyond that which
/// provides.
///
- protected UdpClient Client
+ protected Socket Client
{
get { return this.m_client; }
set { this.m_client = value; }
@@ -403,7 +403,7 @@
try
{
Byte [] buffer = m_encoding.GetBytes(RenderLoggingEvent(loggingEvent).ToCharArray());
- this.Client.Send(buffer, buffer.Length, this.RemoteEndPoint);
+ this.Client.SendTo(buffer, this.RemoteEndPoint);
}
catch (Exception ex)
{
@@ -472,22 +472,13 @@
{
try
{
- if (this.LocalPort == 0)
+ this.Client = new Socket(RemoteAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
+ this.Client.Blocking = false;
+
+ if (this.LocalPort != 0)
{
-#if NETCF
- this.Client = new UdpClient();
-#else
- this.Client = new UdpClient(RemoteAddress.AddressFamily);
-#endif
+ this.Client.Bind(new IPEndPoint(0, this.LocalPort));
}
- else
- {
-#if NETCF
- this.Client = new UdpClient(this.LocalPort);
-#else
- this.Client = new UdpClient(this.LocalPort, RemoteAddress.AddressFamily);
-#endif
- }
}
catch (Exception ex)
{
@@ -531,7 +522,7 @@
/// The instance that will be used for sending the
/// logging events.
///
- private UdpClient m_client;
+ private Socket m_client;
///
/// The encoding to use for the packet.