我將應用程式配置為將日志發送到彈性搜索。我使用https://www.elastic.co/cloud/ 一切似乎都很好,除了一件事:日志似乎沒有“訊息”欄位(messageTemplate 在那里)。我檢查了提琴手,似乎發布 json 的請求缺少這個欄位,所以我認為問題出在圖書館的某個地方。有誰知道可能是什么原因?
發送到elastic的json示例:
{"index":{"_type":"_doc","_index":"logstash-2021.11.08"}}
{"@timestamp":"2021-11-08T19:53:37.5417821 02:00","level":"Information","messageTemplate":"Started notification {Notification}","fields":{"Notification":"SendResetPasswordNotification","SourceContext":"****LoggingMediator","ActionId":"59629d88-ab88-476f-a258-8d984142b223","ActionName":"*****AccountController.SendReset)","RequestId":"0HMD2S2FGO4IP:00000001","RequestPath":"/api/v1/account/sendReset","SpanId":"|565f9fbf-466b083f5ac1a8f5.","TraceId":"565f9fbf-466b083f5ac1a8f5","ParentId":"","ConnectionId":"0HMD2S2FGO4IP","Client":null,"CorrelationId":"a892d398-6a79-47a4-aaf7-d83e12cbd468","Application":"****.Identity.Api","Version":"1.0.0.0","Environment":"Dev"}}
配置:
"Serilog": {
"Using": [
"Serilog.Sinks.ElasticSearch"
],
"Enrich": [
"FromLogContext"
],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "url to elastic",
"autoRegisterTemplate": true,
"autoRegisterTemplateVersion": "ESv7",
"customFormatter": "Serilog.Formatting.Elasticsearch.ExceptionAsObjectJsonFormatter, Serilog.Formatting.Elasticsearch"
}
}
]
}
uj5u.com熱心網友回復:
所以原因是默認情況下Serilog.Formatting.Elasticsearch.ExceptionAsObjectJsonFormatter將renderMessage標志設定為 false。解決方案是創建派生自的自定義格式化程式ExceptionAsObjectJsonFormatter并將建構式中的 renderMessage 標志設定為 true
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/357706.html
標籤:弹性搜索 串行 serilog-sinks-elasticsearch
上一篇:Elasticsearch:從物件映射的特定物件中獲取最大值和最小值
下一篇:如何根據條件洗掉一系列行?
