[英]Serilog property destructuring doesn't work consistently?
I am trying to enrich my Serilog log context with an object and have it's properties show up as destructured in Elasticsearch.我正在尝试使用 object 来丰富我的 Serilog 日志上下文,并使其属性在 Elasticsearch 中显示为已解构。 This works fine when I am using
LogContext.PushProperty
:当我使用
LogContext.PushProperty
时,这很好用:
var conductorContext = new
{
WorkflowInstanceId,
task.TaskId,
TaskName = task.WorkflowTask.Name,
TaskType,
task.InputData
};
using (LogContext.PushProperty("ConductorContext", conductorContext, destructureObjects: true))
The ConductorContext
object is neatly destructured and it's properties are individually accessible in Elasticsearch: ConductorContext
object 被巧妙地解构,它的属性可以在 Elasticsearch 中单独访问:
"fields" : {
"ConductorContext" : {
"WorkflowInstanceId" : "8dca7ebd-4b68-4389-ab98-136bbdf11484",
"TaskId" : "29cef277-dc33-45a6-8b07-65a4de327f49",
"TaskName" : "LoadAangrijpOmsDataTask",
"TaskType" : "LoadAangrijpOmsDataTask",
"InputData" : null
}
}
However, when I use WithProperty
(I want to add a global object) as follows (in my Program.cs:Main
method:但是,当我按如下方式使用
WithProperty
(我想添加一个全局对象)时(在我的Program.cs:Main
方法中:
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("NomadContext", new
{
AllocationId = Environment.GetEnvironmentVariable("NOMAD_ALLOC_ID"),
AllocationName = Environment.GetEnvironmentVariable("NOMAD_ALLOC_NAME"),
JobId = Environment.GetEnvironmentVariable("NOMAD_JOB_ID"),
JobName = Environment.GetEnvironmentVariable("NOMAD_JOB_NAME"),
GroupName = Environment.GetEnvironmentVariable("NOMAD_GROUP_NAME"),
TaskName = Environment.GetEnvironmentVariable("NOMAD_TASK_NAME")
}, destructureObjects: true)
The NomadContext
shows up as a string in Elasticsearch: NomadContext
在 Elasticsearch 中显示为字符串:
"fields" : {
"NomadContext" : "{ AllocationId = 293dd620-955c-7f8d-b6b5-9a36546bd29d, AllocationName = da_pub_worker.group_da_pub_worker[1], JobId = , JobName = da_pub_worker, GroupName = group_da_pub_worker, TaskName = task_da_pub_worker }"
}
I cannot figure out why the first works and the latter doesn't.我无法弄清楚为什么第一个有效而后者无效。 What am I missing?
我错过了什么?
I am using the Serilog.Sinks.Elasticsearch package.我正在使用 Serilog.Sinks.Elasticsearch package。
The problem was not in Serilog or in the Serilog.Sinks.Elasticsearch package, but in the configuration of my ELK stack itself.问题不在 Serilog 或 Serilog.Sinks.Elasticsearch package 中,而是在我的 ELK 堆栈本身的配置中。
Deleting and re-creating my indices made the NomadContext come up properly destructured.删除和重新创建我的索引使 NomadContext 正确解构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.