protected void Send(SyslogMessage message, ISyslogMessageSerializer serializer, bool flush = true) { if(transportStream == null) { throw new IOException("No transport stream exists"); } var datagramBytes = serializer.Serialize(message); if (messageTransfer.Equals(MessageTransfer.OctetCounting)) { byte[] messageLength = Encoding.ASCII.GetBytes(datagramBytes.Length.ToString()); transportStream.Write(messageLength, 0, messageLength.Length); transportStream.WriteByte(32); // Space } transportStream.Write(datagramBytes, 0, datagramBytes.Length); if (messageTransfer.Equals(MessageTransfer.NonTransparentFraming)) { transportStream.WriteByte(trailer); // LF } if (flush && !(transportStream is NetworkStream)) transportStream.Flush(); }
protected void Send(SyslogMessage message, ISyslogMessageSerializer serializer, bool flush = true) { if (transportStream == null) { throw new IOException("No transport stream exists"); } var datagramBytes = serializer.Serialize(message); if (messageTransfer.Equals(MessageTransfer.OctetCounting)) { byte[] messageLength = Encoding.ASCII.GetBytes(datagramBytes.Length.ToString()); transportStream.Write(messageLength, 0, messageLength.Length); transportStream.WriteByte(32); // Space } transportStream.Write(datagramBytes, 0, datagramBytes.Length); if (messageTransfer.Equals(MessageTransfer.NonTransparentFraming)) { transportStream.WriteByte(trailer); // LF } if (flush && !(transportStream is NetworkStream)) { transportStream.Flush(); } }
protected void Send(SyslogMessage message, ISyslogMessageSerializer serializer, bool flush = true) { if (transportStream == null) { throw new System.IO.IOException("No transport stream exists"); } using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { byte[] datagramBytes = serializer.Serialize(message); if (messageTransfer.Equals(MessageTransfer.OctetCounting)) { byte[] messageLength = System.Text.Encoding.ASCII.GetBytes(datagramBytes.Length.ToString(System.Globalization.CultureInfo.InvariantCulture)); memoryStream.Write(messageLength, 0, messageLength.Length); memoryStream.WriteByte(32); // Space } memoryStream.Write(datagramBytes, 0, datagramBytes.Length); if (messageTransfer.Equals(MessageTransfer.NonTransparentFraming)) { memoryStream.WriteByte(trailer); // LF } transportStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); } if (flush && !(transportStream is System.Net.Sockets.NetworkStream)) { transportStream.Flush(); } }
protected void SendToSyslog(SyslogMessage message, ISyslogMessageSerializer serializer) { int priority = CalculatePriorityValue(message.Facility, message.Severity); serializer = EnsureValidSerializer(serializer); byte[] data = serializer.Serialize(message); syslog(priority, "%s", data); }
protected void SendToSyslog(SyslogMessage message, ISyslogMessageSerializer serializer) { int priority = CalculatePriorityValue(message.Facility, message.Severity); serializer = EnsureValidSerializer(serializer); byte[] data = serializer.Serialize(message); syslog(priority, "%s", data); }
/// <summary> /// Serializes the message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> private byte[] SerializeMessage(SyslogMessage message) { byte[] data; using (var stream = new MemoryStream()) { _serializer.Serialize(message, stream); data = stream.ToArray(); } return(data); }
public static byte[] Serialize(this ISyslogMessageSerializer serializer, SyslogMessage message) { byte[] datagramBytes; using (var stream = new MemoryStream()) { serializer.Serialize(message, stream); stream.Position = 0; datagramBytes = new byte[stream.Length]; stream.Read(datagramBytes, 0, (int)stream.Length); } return(datagramBytes); }
private void SerializeMessageToStream(SyslogMessage message, ISyslogMessageSerializer serializer, Stream memoryStream) { var datagramBytes = serializer.Serialize(message); if (messageTransfer.Equals(MessageTransfer.OctetCounting)) { var messageLength = Encoding.ASCII.GetBytes(datagramBytes.Length.ToString()); memoryStream.Write(messageLength, 0, messageLength.Length); memoryStream.WriteByte(32); // Space } memoryStream.Write(datagramBytes, 0, datagramBytes.Length); if (messageTransfer.Equals(MessageTransfer.NonTransparentFraming)) { memoryStream.WriteByte(trailer); // LF } }
public void Send(SyslogMessage message, ISyslogMessageSerializer serializer) { byte[] datagramBytes = serializer.Serialize(message); udpClient.Send(datagramBytes, datagramBytes.Length); }
public void Send(SysLog.Message message, ISyslogMessageSerializer serializer) { byte[] datagramBytes = serializer.Serialize(message); udpClient.Send(datagramBytes, datagramBytes.Length); }
public Task SendAsync(SyslogMessage message, ISyslogMessageSerializer serializer) { var datagramBytes = serializer.Serialize(message); return(udpClient.SendAsync(datagramBytes, datagramBytes.Length)); }
/// <summary> /// Сериализует сообщение в формате Syslog в поток /// </summary> /// <param name="message">Сообщение в формате Syslog</param> /// <param name="stream">Поток для помещения сериализованного сообщения</param> public void Serialize(SyslogMessage message, Stream stream) { _syslogMessageSerializer.Serialize(message, stream); }