DataDog / serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
Apache License 2.0
60 stars 41 forks source link

Fixes Newtonsoft wrong serialization when default serialize settings is changed #70

Closed ThiagoBarradas closed 1 year ago

ThiagoBarradas commented 2 years ago

When we have a default configuration like:

JsonConvert.DefaultSettings = () => new JsonSerializerSettings(...);

It can change sink behaviour.

In my tests, changing ContractResolver (to snakecase for example), it changes root properties do default contract resolver instead keep original value.

To fix it, I create OriginalCaseNamingResolver to keep original property name instead of default configuration.

I add a IsoDateTimeConverter too, to fix the same behavior (when default exists, timestamp is changed to another time)

--

Temporarily, I add a copy of project with this changes in my project until my PR is merged

Thanks!

yurisouza commented 2 years ago

This is exactly what I need!

ThiagoBarradas commented 2 years ago

Hello @AndrewMD5, can you review my PR please?

=)

gh123man commented 2 years ago

Hi @ThiagoBarradas Thanks for the contribution, sorry for the late response. Can you provide an example of how the current implementation is broken? I would like to reproduce it to validate this fix.

Or alternatively you could add a unit test demonstrating the fix.

gh123man commented 1 year ago

We removed the JSON serializer in favor of exposing the underlying ITextFormatter interface in https://github.com/DataDog/serilog-sinks-datadog-logs/pull/86

With this change you can format your logs however you like without library changes.