Skip to content

Commit

Permalink
fix: don't post empty HTTP messages
Browse files Browse the repository at this point in the history
Prevent posting HTTP messages without any log events.
  • Loading branch information
FantasticFiasco committed Aug 13, 2017
1 parent d701353 commit df541ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and is followi

- [#22](https://github.com/FantasticFiasco/serilog-sinks-http/issues/22) Batch formatter `ArrayBatchFormatter` which is compatible with the Logstash HTTP input plugin configured to use the JSON codec

### Fixed

- Prevent posting HTTP messages without any log events

## [4.0.0] - 2017-06-17

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Serilog.Sinks.Http.BatchFormatters
{
Expand Down Expand Up @@ -58,6 +59,12 @@ public override void Format(IEnumerable<string> logEvents, TextWriter output)
if (output == null)
throw new ArgumentNullException(nameof(output));

// Abort if sequence of log events is empty
if (!logEvents.Any())
{
return;
}

output.Write("[");

var delimStart = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Serilog.Sinks.Http.BatchFormatters
{
Expand Down Expand Up @@ -60,6 +61,12 @@ public override void Format(IEnumerable<string> logEvents, TextWriter output)
if (output == null)
throw new ArgumentNullException(nameof(output));

// Abort if sequence of log events is empty
if (!logEvents.Any())
{
return;
}

output.Write("{\"events\":[");

var delimStart = string.Empty;
Expand Down

0 comments on commit df541ac

Please sign in to comment.