Exemple #1
0
        public void Send(GelfMessage message)
        {
            EstablishConnection();
            var bytes = _messageSerializer.SerializeToStringBytes(message);

            _clientStream.Write(bytes, 0, bytes.Length);
            if (_useNullByteDelimiter)
            {
                // write final NULL byte indicating that one complete GELF message has been written
                _clientStream.WriteByte(0);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends a single <see cref="GelfMessage" /> to GrayLog.
        /// </summary>
        /// <param name="message">The <see cref="GelfMessage" /> to send.</param>
        public void Send(GelfMessage message)
        {
            var msgBytes = _messageSerializer.SerializeToStringBytes(message);

            if (msgBytes.Length > MinMessageSizeBeforeCompressing)
            {
                using (var inputStream = new MemoryStream(msgBytes))
                    using (var outputStream = new MemoryStream(msgBytes.Length))
                        using (var writer = new GZipWriter(outputStream, new GZipWriterOptions()
                        {
                            CompressionType = CompressionType.GZip, LeaveStreamOpen = false
                        }))
                        {
                            writer.Write(string.Empty, inputStream);
                            msgBytes = outputStream.GetBuffer();
                        }
            }
            using (var udpClient = new UdpClient())
                foreach (var bytes in _chunkEncoder.Encode(msgBytes))
                {
                    udpClient.Send(bytes, bytes.Length, GetEndPoint());
                }
        }