Serilog 删除 $type 属性
Serilog remove $type property
我有以下记录器配置
new LoggerConfiguration()
.ReadFrom.Configuration(configuration.GetSection("MyConfig"))
.WriteTo.Console(new CompactJsonFormatter())
.Destructure.UsingAttributes()
.Enrich.WithProperty("CorrelationIdHeader", "someId")
.CreateLogger()
我正在执行:
logger.Information("{@MyObject}", new MyObject {SomeVal = ""});
控制台输出 json 总是包含 $type 属性,我想删除它
{
...
"$type": "MyObject"
}
如何在配置过程中删除 $type?谢谢
您需要使用不输出类型的 JsonValueFormatter
构造 CompactJsonFormatter
。您可以通过在创建 JsonValueFormatter
:
时将 null
指定为 typeTagName
来实现
new CompactJsonFormatter(new JsonValueFormatter(null))
我有以下记录器配置
new LoggerConfiguration()
.ReadFrom.Configuration(configuration.GetSection("MyConfig"))
.WriteTo.Console(new CompactJsonFormatter())
.Destructure.UsingAttributes()
.Enrich.WithProperty("CorrelationIdHeader", "someId")
.CreateLogger()
我正在执行:
logger.Information("{@MyObject}", new MyObject {SomeVal = ""});
控制台输出 json 总是包含 $type 属性,我想删除它
{
...
"$type": "MyObject"
}
如何在配置过程中删除 $type?谢谢
您需要使用不输出类型的 JsonValueFormatter
构造 CompactJsonFormatter
。您可以通过在创建 JsonValueFormatter
:
null
指定为 typeTagName
来实现
new CompactJsonFormatter(new JsonValueFormatter(null))