3

I want to configure Serilog to log date in UTC format but currently the timezone of the server is used. We are using the following configuration file:

{
  "Serilog": {
    "Using": [
      "Serilog.Sinks.Console",
      "Serilog.Sinks.File"
    ],
    "LevelSwitches": { "$controlSwitch": "Verbose" },
    "MinimumLevel": { "ControlledBy": "$controlSwitch" },
    "WriteTo": [
      {
        "Name": "Logger",
        "Args": {
          "configureLogger": {
            "WriteTo": [
              {
                "Name": "File",
                "Args": {
                  "outputTemplate": "{Timestamp:yyyy-MM-dd:HH:mm:ss.ffff} - {Message,-20:l}{NewLine}{Exception}",
                  "path": "./logs/my.log"
                }
              }
            ]
          }
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithExceptionDetails", "ProcessId" ]
  }
}

I know it can be done by writing custom enricher, but is there any simple solution for this with a template?

Sheinar
  • 362
  • 3
  • 14

1 Answers1

-1

Try {Timestamp:G}

So, in your code:

"outputTemplate": "{Timestamp:G} - {Message,-20:l}{NewLine}{Exception}",
Husam Ebish
  • 4,893
  • 2
  • 22
  • 38