Exemplo n.º 1
0
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            byte[] body;
            using (var render = new StringWriter())
            {
                _formatter.Format(logEvent, render);
                body = Encoding.UTF8.GetBytes(render.ToString());
            }

            var eventHubData = new EventData(body)
            {
                PartitionKey = Guid.NewGuid().ToString()
            };

            _eventDataAction?.Invoke(eventHubData, logEvent);

            if (_compressionTreshold != null && eventHubData.SerializedSizeInBytes > _compressionTreshold)
            {
                eventHubData = eventHubData.AsCompressed();
            }

            using (var transaction = new TransactionScope(TransactionScopeOption.Suppress))
            {
                _eventHubClient.Send(eventHubData);
            }
        }
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            byte[] body;

            using (var render = new StringWriter())
            {
                _formatter.Format(logEvent, render);
                body = Encoding.UTF8.GetBytes(render.ToString());
            }

            var eventHubData = new EventData(body)
            {
#if NET45
                PartitionKey = Guid.NewGuid().ToString()
#endif
            };

            eventHubData.Properties.Add("LogItemId", Guid.NewGuid().ToString());
#if NET45
            if (_compressionTreshold != null && eventHubData.SerializedSizeInBytes > _compressionTreshold)
            {
                eventHubData = eventHubData.AsCompressed();
            }

            using (var transaction = new TransactionScope(TransactionScopeOption.Suppress))
            {
                _eventHubClient.Send(eventHubData);
            }
#else
            _eventHubClient.SendAsync(eventHubData).Wait();
#endif
        }
Exemplo n.º 3
0
        private EventData ConvertLogEventToEventData(LogEvent logEvent, string batchPartitionKey = null)
        {
            if (batchPartitionKey == null)
            {
                batchPartitionKey = Guid.NewGuid().ToString();
            }

            byte[] body;
            using (var render = new StringWriter())
            {
                _formatter.Format(logEvent, render);
                body = Encoding.UTF8.GetBytes(render.ToString());
            }

            var eventHubData = new EventData(body)
            {
#if NET45
                PartitionKey = batchPartitionKey
#endif
            };

            eventHubData = eventHubData.AsCompressed();

            eventHubData.Properties.Add("LogItemId", Guid.NewGuid().ToString());
            return(eventHubData);
        }
        private EventData ConvertLogEventToEventData(LogEvent logEvent)
        {
            byte[] body;
            using (var render = new StringWriter())
            {
                _formatter.Format(logEvent, render);
                body = Encoding.UTF8.GetBytes(render.ToString());
            }

            var eventHubData = new EventData(body);

            eventHubData = eventHubData.AsCompressed();

            eventHubData.Properties.Add("LogItemId", Guid.NewGuid().ToString());
            return(eventHubData);
        }
Exemplo n.º 5
0
        private EventData ConvertLogEventToEventData(LogEvent logEvent, string batchPartitionKey = null)
        {
            if (batchPartitionKey == null)
            {
                batchPartitionKey = Guid.NewGuid().ToString();
            }

            byte[] body;
            using (var render = new StringWriter())
            {
                _formatter.Format(logEvent, render);
                body = Encoding.UTF8.GetBytes(render.ToString());
            }

            var eventHubData = new EventData(body)
            {
                PartitionKey = batchPartitionKey
            };

            eventHubData = eventHubData.AsCompressed();

            _eventDataAction?.Invoke(eventHubData, logEvent);
            return(eventHubData);
        }