예제 #1
0
        /// <summary>
        /// Publishes a Gelf message to the specified Graylog server.
        /// </summary>
        public void Publish(GelfMessage message)
        {
            var serializedGelfMessage = JsonConvert.SerializeObject(message, Formatting.Indented);

            byte[] bytes = serializedGelfMessage.GzipMessage(Constants.Encoding);

            if (Constants.MaxChunkSize < bytes.Length)
            {
                var chunkCount = (bytes.Length / Constants.MaxChunkSize) + 1;

                if (chunkCount > Constants.MaxChunkCount)
                {
                    throw new GelfMessageTooBigException($"Message of size {bytes.Length} will break up into {chunkCount} chunks, which is greater than maximum of GELF standard {Constants.MaxChunkCount}");
                }

                var messageId = ChunkedMessageHelper.GenerateMessageId();
                var state     = new UdpState {
                    SendClient = client, Bytes = bytes, ChunkCount = chunkCount, MessageId = messageId, SendIndex = 0
                };
                var messageChunkFull = ChunkedMessageHelper.GetMessageChunkFull(state.Bytes, state.MessageId, state.SendIndex, state.ChunkCount);
                client.BeginSend(messageChunkFull, messageChunkFull.Length, SendCallback, state);
            }
            else
            {
                var state = new UdpState {
                    SendClient = client, Bytes = bytes, ChunkCount = 0, MessageId = string.Empty, SendIndex = 0
                };
                client.BeginSend(bytes, bytes.Length, SendCallback, state);
            }
        }
예제 #2
0
        /// <summary>
        /// Publishes a Gelf message to the specified Graylog server.
        /// </summary>
        public void Publish(GelfMessage message)
        {
            var serializedGelfMessage = JsonConvert.SerializeObject(message, Formatting.Indented);

            byte[] bytes = serializedGelfMessage.GzipMessage(Constants.Encoding);

            if (Constants.MaxChunkSize < bytes.Length)
            {
                var chunkCount = (bytes.Length / Constants.MaxChunkSize) + 1;
                var messageId  = ChunkedMessageHelper.GenerateMessageId();
                var state      = new UdpState {
                    SendClient = client, Bytes = bytes, ChunkCount = chunkCount, MessageId = messageId, SendIndex = 0
                };
                var messageChunkFull = ChunkedMessageHelper.GetMessageChunkFull(state.Bytes, state.MessageId, state.SendIndex, state.ChunkCount);
                client.BeginSend(messageChunkFull, messageChunkFull.Length, SendCallback, state);
            }
            else
            {
                var state = new UdpState {
                    SendClient = client, Bytes = bytes, ChunkCount = 0, MessageId = string.Empty, SendIndex = 0
                };
                client.BeginSend(bytes, bytes.Length, SendCallback, state);
            }
        }