serilog-contrib/serilog-sinks-azuretablestorage

Writing to AzureTableStorage fail when using NodaTime

etbuilder opened this issue · 2 comments

When using Nodatime in my .net core project, the following is added to guarantee serialization of Nodatime

services.AddMvc()
    .AddJsonOptions(options =>
{
    options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    options.SerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); // noda serialization // this will diable automatic handeling of datetime

});

var serializer = new JsonSerializerSettings() {
    ContractResolver = new CamelCasePropertyNamesContractResolver(),
};
serializer.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
JsonConvert.DefaultSettings = () => serializer;

The problem arise when serializing the
Timestamp = log.Timestamp.ToUniversalTime().DateTime

When removing the conversion, the logging to azure table works again
Timestamp = log.Timestamp.ToUniversalTime() without converting to DateTime as the TimeStamp is of type DateTimeOffset

Added Pull request #52 to fix the issue.

No longer relevant. The sink has been rewritten in version 8. Please open a new issue if still having problems.