serilog日期为UTC格式
我想将Serilog配置为以UTC格式进行日期日期,但目前使用了服务器的时区。我们正在使用以下配置文件:
{
"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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将时间转换为UTC。但是您没有任何格式的选择。
会给你的
是对我有用的JSON。
You can convert the time to UTC. But you don't have any options for the format.
Will give you
Here is the json that worked for me.
尝试
{timestamp:g}
,因此,在您的代码中:
Try
{Timestamp:G}
So, in your code: