If Timestamp column is set to UTC, Timestamp property in LogEvent column should be UTC too
I have the following configuration with Serilog.Sinks.MSSqlServer v9.0.02:
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "LogsConnection",
"sinkOptionsSection": {
"tableName": "Logs",
"autoCreateSqlTable": true
},
"restrictedToMinimumLevel": "Information",
"columnOptionsSection": {
"addStandardColumns": [ "LogEvent" ],
"removeStandardColumns": [ "MessageTemplate", "Properties" ],
"timeStamp": {
"columnName": "Timestamp",
"convertToUtc": true,
},
"logEvent": {
"excludeAdditionalProperties": false,
"excludeStandardColumns": false
}
}
}
}
],
"Enrich": [ "FromLogContext" ]
}
In particular, I have set the convertToUtc property of timeStamp column to true. With this configuration, I expect that also the Timestamp property in the JSON LogEvent column will be saved as UTC. However, I see values like this:
{
"Timestamp":"2025-12-12T08:30:25.4094643",
"Level":"Information",
"Message":"Request finished \"HTTP/2\" \"GET\" \"https\"://\"localhost:7164\"\"\"\"/api/ping\"\"\" - 200 0 null 39.3178ms",
// ...
}
Where Timestamp property is missing the Z modifier.
hi @marcominerva!
This is because convertToUtc is a column option which is specific to the TimeStamp column. It is only applied to the output of this particular column and does not modify the timestamp property of the log event in general.
We could though add a new sink option convertTimeStampToUtc which is applied to the timestamp in the log event and hence converts it for all columns where it can appear.
The value of the Timestamp property in LogEvent already takes into account that the timeStamp column is converted to UTC (see line 75 below):
https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/1d78885dea91fad65307bea068479198945d2a9d/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/StandardColumnDataGenerator.cs#L73-L81
Therefore, I think line 80 should also be updated to consider the value of ConvertToUtc:
return new KeyValuePair<string, object>(_columnOptions.TimeStamp.ColumnName,
_columnOptions.TimeStamp.ConvertToUtc ? dateTimeOffset.UtcDateTime : dateTimeOffset.DateTime);
This ensures consistency in the use of ConvertToUtc property.
I have opened a PR to apply this fix, please let me know what you think about.