Closed tautvydasversockas closed 1 year ago
Hello! Thanks for dropping us a line.
DateOnly
is treated as a scalar value in Serilog 2.12, in line with how DateTime
, DateTimeOffset
, and friends are handled:
https://github.com/serilog/serilog/blob/dev/src/Serilog/Formatting/Json/JsonValueFormatter.cs#L509
This has been the case for a long time, but my guess is that the earlier version of this package that you were depending on brought in an earlier version of Serilog, released before DateOnly
was in wide use.
Sorry about the breakage, here; there are two workarounds you might try.
First, you might change the fields.MyDto
field name so that Elastic keeps separate indexes for the old and new versions of the data.
Or second, you can Destructure.ByTransforming<MyDto>(() => ...)
, using the callback to convert MyDto
into a similar type that uses a replacement struct instead of DateOnly
with the various properties (Year
, Month
, ...) exposed.
Let me know if either does the trick!
Hello, thanks for a quick reply. I really appreciate you providing multiple workarounds! However, at the moment I fixed the problem by rebuilding ElasticSearch
indexes so there's no urgent problem from my side. The reason for this bug report is to inform you (and other users that might face the same issue in the future) about this breakage. Have a lovely day!
Awesome, thanks. Closing this as by design 👍
Description
My logging stack is a combination of
Serilog
andELK
stack. I upgradedSerilog.AspNetCore
form version6.1.0
to version7.0.0
. I believe this update might have impacted how structured logging treatsDateOnly
properties. I couldn't find any documentation about it though. As a result of this upgrade,ElasticSearch
indexes couldn't parseDateOnly
data types which meant that the logs were not visible.Code that was used for logging (obviously I simplified it a bit):
What I saw in the logs before the
Serilog.AspNetCore
upgrade:What I saw in the logs after the
Serilog.AspNetCore
upgrade:What I saw in
ElasticSearch
logs:What I saw in the logs after the
Serilog.AspNetCore
upgrade and after I rebuilt my indexes inElasticSearch
:Question
Is this breaking change expected? Should this be documented somewhere (i.e. release notes)?
Versions
.NET
-net7.0
Serilog.AspNetCore
-7.0.0
Serilog.Sinks.LogstashHttp
-1.2.0
Serilog.Sinks.PeriodicBatching
-3.1.0
ElasticSearch
-v 7.17.5