【问题标题】:Serilog date in UTC formatSerilog date in UTC format
【发布时间】:2022-12-27 23:22:23
【问题描述】:

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?

【问题讨论】:

    标签: datetime-format serilog serilog-sinks-file


    【解决方案1】:

    Try {Timestamp:G}

    So, in your code:

    "outputTemplate": "{Timestamp:G} - {Message,-20:l}{NewLine}{Exception}",
    

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多