Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Serilog 4.0 built-in UtcTimestamp token in output template #164

Open
ManuelRin opened this issue Dec 2, 2024 · 0 comments
Open

Comments

@ManuelRin
Copy link

Package affected: Serilog.Sinks.Console 6.0.0
Target framework: net8.0
OS: Windows 10

Serilog 4.0.0 came with a new built-in support for an UtcTimestamp token in addition to the existing Timestamp token for output templates. This feature was introduced via Serilog PR #2051.

The Serilog.Sinks.Console package in version 6.0.0 (although requiring Serilog 4.0.0+) doesn't seem to support this new built-in token yet. It would be great if support could be added to Serilog.Sinks.Console as well.

Repro steps:

An output template like the following (from the readme example):

    .WriteTo.Console(
        outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")

will output the log entry's timestamp in local time (ignoring the time zone offset).

Now change the output template to use the new Serilog built-in UtcTimestamp token like this:

    .WriteTo.Console(
        outputTemplate: "[{UtcTimestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")

Actual behavior:

  • The log entry timestamp is missing from the formatted output written to the console. This is because the UtcTimestamp token is unknown and no such property was enhanced.

Expected behavior:

  • The console sink recognizes the UtcTimestamp as a built-in token and converts the event log's Timestamp to UTC and formats the UTC timestamp according to the (optional) format string.

Let me know if need more info is needed!
Best regards!

ManuelRin added a commit to ManuelRin/serilog-sinks-console that referenced this issue Dec 3, 2024
ManuelRin added a commit to ManuelRin/serilog-sinks-console that referenced this issue Dec 3, 2024
ManuelRin added a commit to ManuelRin/serilog-sinks-console that referenced this issue Dec 4, 2024
- assert that UtcTimestamp in default format (no custom format string) renders without the +00:00 time-zone suffix.

Relates to serilog#164
ManuelRin added a commit to ManuelRin/serilog-sinks-console that referenced this issue Dec 4, 2024
…standard formating

- keep render performance in mind / i.e. keep optimizations from serilog#134
- ensure UtcTimestamp without format string is rendered without " +00:00" suffix by rendering as DateTime (same behavior as Serilog's MessageTemplateTextFormatter)

Relates to serilog#164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants