Serilog SQL Server Sink 使用 UTC 作为时间戳

问题描述 投票:0回答:1

使用通过 json 文件配置的 SQL Server 接收器时,时间戳不是 UTC。

在执行这项工作的代码中:

columnOptions.TimeStamp.ConvertToUtc = true;

如何在 JSON 配置文件中执行相同的操作?

这是完整的当前 JSON 配置文件:

{
    "Serilog": {
        "MinimumLevel": "Verbose",
        "WriteTo": [
            {
                "Name": "Console",
                "Args": {
                    "restrictedToMinimumLevel": "Debug"
                }
            },
            {
                "Name": "File",
                "Args": {
                    "path": "\\Logs\\log.log",
                    "rollingInterval": "Day",
                    "restrictedToMinimumLevel": "Error"
                }
            },
            {
                "Name": "MSSqlServer",
                "Args": {
                    "restrictedToMinimumLevel": "Debug",
                    "connectionString": "XXXX",
                    "sinkOptions": {
                        "autoCreateSqlTable": true,
                        "tableName": "Logs"
                    },
                    "columnOptionsSection": {
                        "disableTriggers": true,
                        "clusteredColumnstoreIndex": false,
                        // Add an id column
                        "primaryKey": { "ColumnName": "Id" },
                        // Add the event in json for searching
                        "addStandardColumns": [ "LogEvent" ],
                        // This is the same info as the LogEvnt but in XML.
                        "removeStandardColumns": [ "Properties" ],
                        // Add a Process column 
                        "additionalColumns": [
                            {
                                "ColumnName": "Process",
                                "DataType": "varchar",
                                "DataLength": 255
                            }
                        ]
                    }
                }
            }
        ],
        "Enrich": [ "FromLogContext" ]
    }
}

添加到

UseUtcTimestamp
中的
args.sinkOptions
不起作用。

"Args": {
          "connectionString": "XXXX",
          "sinkOptions": {
            "UseUtcTimestamp": true
          }
        }
c# .net serilog serilog.sinks.mssqlserver
1个回答
0
投票

它应该在

columnOptionsSection
(docs):

"columnOptionsSection": {
    // ...
    "timeStamp": { "columnName": "Timestamp", "convertToUtc": true },
    // ...
}
© www.soinside.com 2019 - 2024. All rights reserved.