Skip to content

JSON outputTemplate in Serilog Console log not showing Timestamp #163

@mtotaro

Description

@mtotaro

Hi 👋,

I'm experiencing an issue with the outputTemplate in Serilog when trying to log JSON-formatted messages to the console. Instead of rendering the actual values, it outputs placeholder words such as {Timestamp:HH:mm:ss}, {Level:w3}, etc. I expected to see actual timestamps, severity levels, and messages in the log output.

Details:

Serilog Package ID and Version: Serilog 4.0.1
Toolchain, Framework, and OS: .NET 8 SDK on Windows 10.
Configuration:
Here’s a sample configuration for WriteTo in appsettings.json:

"WriteTo": [
    {
        "Name": "AmazonCloudWatch",
        "Args": {
            "logGroup": "test",
            "logStreamPrefix": "app",
            "region": "eu-west-1",
            "restrictedToMinimumLevel": "Information",
            "createLogGroup": true
        }
    },
    {
        "Name": "Console",
        "Args": {
            "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
            "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
            "outputTemplate": "{\"time\": \"{Timestamp:HH:mm:ss}\", \"severity\": \"{Level:w3}\", \"msg\": \"{Message:lj}\", \"exception\": \"{Exception}\", \"correlationID\": \"{TraceId}\" }{NewLine}"
        }
    }
]

Current Behavior:

The console output currently shows the following instead of the actual values:

{"time": "{Timestamp:HH:mm:ss}", "severity": "inf", "msg": "Request finished HTTP/2 GET https://localhost:7026/_vs/browserLink - 200 null text/javascript; charset=UTF-8 215.1437ms", "exception": "", "correlationID": "e08cdf60b8bb30c12f7ae2db8f592935" }}

As shown, placeholder such as {Timestamp:HH:mm:ss} is not being replaced with actual values.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions