HttpRequestMessage BuildRequest(IEnumerable <LogEvent> logEvents)
        {
            var payload            = new StringWriter();
            var eventStringBuilder = new StringBuilder();
            var eventPayload       = new StringWriter(eventStringBuilder);

            foreach (var logEvent in logEvents)
            {
                eventStringBuilder.Clear();

                try
                {
                    _formatter.Format(logEvent, eventPayload);
                }
                catch (Exception exception)
                {
                    LogNonFormattableEvent(logEvent, exception);
                    continue;
                }

                payload.Write(eventStringBuilder.ToString());
            }

            return(new HttpRequestMessage(HttpMethod.Post, GetUploadUrl())
            {
                Content = new StringContent(payload.ToString(), Encoding.UTF8, ElkStreamsApi.EventMimeType)
            });
        }
Ejemplo n.º 2
0
        HttpRequestMessage BuildRequest(IEnumerable <LogEvent> logEvents)
        {
            _eventsStream.Position = 0;

            foreach (var logEvent in logEvents)
            {
                var position = _eventsStream.Position;
                try
                {
                    try
                    {
                        _formatter.Format(logEvent, _eventsWriter);
                    }
                    finally
                    {
                        _eventsWriter.Flush();
                    }
                }
                catch (Exception exception)
                {
                    _eventsStream.Position = position;

                    LogNonFormattableEvent(logEvent, exception);
                }
            }

            return(new HttpRequestMessage(HttpMethod.Post, GetUploadPath())
            {
                Content = new ByteArrayContent(_eventsStream.GetBuffer(), 0, (int)_eventsStream.Position)
            });
        }