@@ -406,28 +406,44 @@ public void TimestampTokenRendersLocalTime()
406
406
{
407
407
var logTimestampWithTimeZoneOffset = DateTimeOffset . Parse ( "2024-09-03T14:15:16.079+02:00" , CultureInfo . InvariantCulture ) ;
408
408
var formatter = new OutputTemplateRenderer ( ConsoleTheme . None ,
409
- "Default Format: {Timestamp} / Custom Format String: {Timestamp:yyyy-MM-dd HH:mm:ss}" ,
409
+ """
410
+ Default Format: {Timestamp}
411
+ Round-trip Standard Format String: {Timestamp:o}
412
+ Custom Format String: {Timestamp:yyyy-MM-dd HH:mm:ss}
413
+ """ ,
410
414
CultureInfo . InvariantCulture ) ;
411
415
var evt = new LogEvent ( logTimestampWithTimeZoneOffset , LogEventLevel . Debug , null ,
412
416
new MessageTemplate ( Enumerable . Empty < MessageTemplateToken > ( ) ) , Enumerable . Empty < LogEventProperty > ( ) ) ;
413
417
var sw = new StringWriter ( ) ;
414
418
formatter . Format ( evt , sw ) ;
415
419
// expect time in local time, unchanged from the input, the +02:00 offset should not affect the output
416
- Assert . Equal ( "Default Format: 09/03/2024 14:15:16 +02:00 / Custom Format String: 2024-09-03 14:15:16" , sw . ToString ( ) ) ;
420
+ Assert . Equal ( """
421
+ Default Format: 09/03/2024 14:15:16 +02:00
422
+ Round-trip Standard Format String: 2024-09-03T14:15:16.0790000+02:00
423
+ Custom Format String: 2024-09-03 14:15:16
424
+ """ , sw . ToString ( ) ) ;
417
425
}
418
426
419
427
[ Fact ]
420
428
public void UtcTimestampTokenRendersUtcTime ( )
421
429
{
422
430
var logTimestampWithTimeZoneOffset = DateTimeOffset . Parse ( "2024-09-03T14:15:16.079+02:00" , CultureInfo . InvariantCulture ) ;
423
431
var formatter = new OutputTemplateRenderer ( ConsoleTheme . None ,
424
- "Default Format: {UtcTimestamp} / Custom Format String: {UtcTimestamp:yyyy-MM-dd HH:mm:ss}" ,
432
+ """
433
+ Default Format: {UtcTimestamp}
434
+ Round-trip Standard Format String: {UtcTimestamp:o}
435
+ Custom Format String: {UtcTimestamp:yyyy-MM-dd HH:mm:ss}
436
+ """ ,
425
437
CultureInfo . InvariantCulture ) ;
426
438
var evt = new LogEvent ( logTimestampWithTimeZoneOffset , LogEventLevel . Debug , null ,
427
439
new MessageTemplate ( Enumerable . Empty < MessageTemplateToken > ( ) ) , Enumerable . Empty < LogEventProperty > ( ) ) ;
428
440
var sw = new StringWriter ( ) ;
429
441
formatter . Format ( evt , sw ) ;
430
442
// expect time in UTC, the +02:00 offset must be applied to adjust the hour
431
- Assert . Equal ( "Default Format: 09/03/2024 12:15:16 / Custom Format String: 2024-09-03 12:15:16" , sw . ToString ( ) ) ;
443
+ Assert . Equal ( """
444
+ Default Format: 09/03/2024 12:15:16
445
+ Round-trip Standard Format String: 2024-09-03T12:15:16.0790000Z
446
+ Custom Format String: 2024-09-03 12:15:16
447
+ """ , sw . ToString ( ) ) ;
432
448
}
433
449
}
0 commit comments