Skip to content

Commit

Permalink
Merge pull request serilog#626 from nblumhardt/dev
Browse files Browse the repository at this point in the history
Use round-trippable floating point formatting in JSON
  • Loading branch information
merbla committed Jan 11, 2016
2 parents 53ee481 + 233dc06 commit b202e5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/Serilog/Formatting/Json/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public JsonFormatter(
{ typeof(uint), WriteToString },
{ typeof(long), WriteToString },
{ typeof(ulong), WriteToString },
{ typeof(float), WriteToString },
{ typeof(double), WriteToString },
{ typeof(float), (v, q, w) => WriteSingle((float)v, w) },
{ typeof(double), (v, q, w) => WriteDouble((double)v, w) },
{ typeof(decimal), WriteToString },
{ typeof(string), (v, q, w) => WriteString((string)v, w) },
{ typeof(DateTime), (v, q, w) => WriteDateTime((DateTime)v, w) },
Expand Down Expand Up @@ -382,6 +382,16 @@ static void WriteBoolean(bool value, TextWriter output)
output.Write(value ? "true" : "false");
}

static void WriteSingle(float value, TextWriter output)
{
output.Write(value.ToString("R", CultureInfo.InvariantCulture));
}

static void WriteDouble(double value, TextWriter output)
{
output.Write(value.ToString("R", CultureInfo.InvariantCulture));
}

static void WriteOffset(DateTimeOffset value, TextWriter output)
{
output.Write("\"");
Expand Down
4 changes: 0 additions & 4 deletions src/Serilog/Sinks/PeriodicBatching/PeriodicBatchingSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
using Serilog.Events;
using System.Threading;

#if !NO_TIMER
using System.Threading;
#endif

namespace Serilog.Sinks.PeriodicBatching
{
/// <summary>
Expand Down

0 comments on commit b202e5e

Please sign in to comment.