markmcdowell/NLog.Targets.ElasticSearch

Problem with exception serialization

FixRM opened this issue · 2 comments

FixRM commented

Hello and thank you for your work. I have very specific exception type that cause

illegal_argument_exception Reason: "mapper [exception.detail.ErrorDetails.Value] cannot be changed from type [text] to [long]

error. It is WCF's FaultException of type Microsoft.Xrm.Sdk.OrganizationServiceFault. Last one has ErrorDetails collection of string-object pairs. Some of the values are strings other are not. Not sure what Value in exception.detail.ErrorDetails.Value is, but it looks like it was "mapped" by Elastic as text for the first time and can't accept other types.

Am I right that this target follow it's own exception formatting and serialization? How can I customize/skip serializing this member? I know that excludedProperties exist but setting it to exception.detail.ErrorDetails doesn't work because, I guess this is not a regular property. Setting maxRecursionLimit is not a good option as well as my exception type has useful information on the same level as ErrorDetails member.

Any suggestions?

Maybe an option could be enableJsonLayout = "true" with Elastic.CommonSchema.NLog. See also #125

Alternative you can define the complete Elastic-Common-Schema using pure NLog JsonLayout. NLog/NLog#4982 (comment) . Then you can then override the Exception-serialization to your liking - https://github.com/NLog/NLog/wiki/How-to-use-structured-logging#customize-object-reflection

FixRM commented

Thanks for the suggestion, @snakefoot. It turns out that maxRecursionLimit works well for my case, but I'll keep enableJsonLayout option in mind for the future.