Elasticsearch记录一个没有记录对象类型的对象

vatpfxk5  于 2023-10-17  发布在  ElasticSearch
关注(0)|答案(1)|浏览(92)

我有一个对象:

var people = new List<Person> {
new Person { Name = "John Doe", Age = 30 },
new Person { Name = "Jane Doe", Age = 25 } };

logger.LogInformation(“{@people }",people);
serilog/elasticsearch日志记录创建以下日志:

[Person { Name: "John Doe", Age: 30 }, Person { Name: "Jane Doe", Age: 25 }]

但我需要以下文件

[{"Name":"John Doe","Age":30},{"Name":"Jane Doe","Age":25}]

我应该如何删除日志实体类型?

uemypmqf

uemypmqf1#

你可以创建一个匿名对象来实现这一点:

people.Select(x => new {Name = x.Name, Age = x.Age})

在选择对象之后,需要序列化此列表。

相关问题