saleem-mirza / serilog-sinks-sqlite

A Serilog sink that writes to SQLite
Apache License 2.0
56 stars 44 forks source link

Using retention period wipes valid data #13

Closed kravlost closed 6 years ago

kravlost commented 6 years ago

If you open a sink with a specified retention period, e.g. 30 days, then all of the existing data in the log is deleted, even if falls within the retention period.

It would also be good if the retention policy was applied more frequently than the retention period if the retention period is long. For a 30-day retention policy it would be useful if (1) you could stop and restart the program without losing old data and (2) the retention policy was applied once an hour (for example) not once every 30 days.

kravlost commented 6 years ago

The issue is with the format of the data written to the database. SQLite only handles certain formats of timestamp, so the DateTime data needs to be converted to the correct format in SQLiteSink.cs lines 134, 135 and 189 by adding .ToString("yyyy-MM-ddTHH:mm:ss"). The records are then correctly deleted on first write.

saleem-mirza commented 6 years ago

@steronydh, please accept my apology for late response. I got caught up in official work schedule. However, thank you very much for reporting issue and suggesting solution. Would you mind creating a pull request?

kravlost commented 6 years ago

Thanks!