Skip to content

Numeric format specifier not respected #1323

@omfgicbf

Description

@omfgicbf

Does this issue relate to a new feature or an existing bug?

  • Bug
  • New Feature

What version of Serilog is affected? Please list the related NuGet package.
Serilog 2.8.0

What is the target framework and operating system? See target frameworks & net standard matrix.

  • netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

Please describe the current behavior?
The hex numeric format specifier does not work unless supplied using standard C# string interpolation. This means I cannot use structured logging if I wish to retain the formatted string in the standard log output.

int status = 16;

log.Error($"Status [0x{status:X8}]"); // "Status [0x00000010]"
log.Error("Status [0x{status:X8}]", status); // "Status [0x16]"
log.Error("Status [0x{0:X8}]", status); // "Status [0x16]"

Please describe the expected behavior?

int status = 16;

log.Error($"Status [0x{status:X8}]"); // "Status [0x00000010]"
log.Error("Status [0x{status:X8}]", status); // "Status [0x00000010]"
log.Error("Status [0x{0:X8}]", status); // "Status [0x00000010]"

Apologies in advance if this is not how it's meant to work. I tried looking for documentation addressing this specific case and couldn't (easily) find it, however, https://github.com/serilog/serilog/wiki/Writing-Log-Events states:

Message templates are a superset of standard .NET format strings, so any format string acceptable to string.Format() will also be correctly processed by Serilog

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions