borisermakof / serilog-sinks-fluentd

A Sink that writes logs into Fluentd
Apache License 2.0
20 stars 31 forks source link

Extra quotes #14

Closed icambron closed 4 years ago

icambron commented 4 years ago

I get extra quotes in Fluentd if I write log statements with string properties:

log.Information("Got Foo: {Foo}", "Bar");

...which results in this in the FluentD json logs (note the extra quotes in "Bar"):

{"Level":"Information","mt":"Got Foo: {Foo}", "Foo": "\"Bar\""}

I confirmed that this is the behavior of this line in FluentSinkClient:

record.Add(log.Key, log.Value.ToString());

Because log.Value.ToString() produces a string that itself contains quotes.

You can see a similar issue here: https://github.com/serilog/serilog/issues/936

The fix suggested there is the equivalent of:

                    if (IsString(log.Value))
                    {
                        record.Add(log.Key, ((ScalarValue)log.Value).Value);
                    }
                    else
                    {
                        record.Add(log.Key, log.Value.ToString());
                    }

I tried that out and it produced output without extra quotes.

Is the current behavior intentional, or would you accept a PR addressing this?


As an addendum--and I'm kind of new to both Serilog and Fluentd--I'd have expected the serializer to have synthesized an @l value too, a field that inlines the arguments into the message. In the example above, that would result in "Got Foo: Bar". Is that something that makes sense to support, or should some downstream piece of Fluentd handle that?