Closed thompson-tomo closed 1 month ago
Note this could very well be an issue with Microsoft.Extensions.Logging but don't believe so based on the fact that the original object being available in the logevent properties dictionary.
You need to use @
to force a json like value in your message see:
https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#formatting-of-the-message
e.g:
MetricDef metricDef = new MetricDef()
_logger.LogInformation(new EventId(88, "Event88"), "Number is {num} and key is {@metricDefKey}", num.ToString(), metricDef);
thanks @Mpdreamz will discuss with NLOG project how i can achieve what i am looking for. As the both example doesn't quite do it as i want my log message to have only 1 property "key" from my class but happy for other properies to be added as labels., Anyway will close this issue as doesn't appear to be an elastic issue
You could send the key as an anonymous object instead?
new { Key = metricDef.Key }
Combined with @
for structured representation in the message itself?
I might not have fully understood the problem though :)
no worries, thanks for the input. For reference I am looking to have all properties from object added as labels and only 1 or more of the properties to be substituted into the message.
So after spending some more time on this, I have managed to get close to what I want by using log generators. with the fix for #397 the most desired outcome will be possible which is to Populate ecs fields with user defined info with minimal effort provided it isn't more the 2 levels deep.
ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): Elastic.CommonSchema.NLog
ECS schema version (e.g. 1.4.0): 8.11
ECS .NET assembly version (e.g. 1.4.2): 8.11
.NET framework / OS: Net 8
Description of the problem, including expected versus actual behavior: When i am passing objects into my log events they are not being serialized as individual properties but rather the ToString of the object
Steps to reproduce:
5.
The expectation is that it would operate as per the microsoft logging ie use the property from the object passed it and in terms of labels each property should be logged as a seperate label using dotted notation.