Exception destructuring in Serilog

前端 未结 3 1132
一个人的身影
一个人的身影 2021-02-05 02:59

Serilog has a convenient way of destructuring objects as shown in this example:

logger.Debug(exception, \"This is an {Exception} text\", exception);
logger.Debug         


        
3条回答
  •  渐次进展
    2021-02-05 03:52

    This should be avoided altogether. Both ElasticSearch and Serilog aren't designed with the idea in mind that you will be serializing arbitrary objects. Logging objects with the conflicting shapes will result in mapping exceptions in ElasticSearch. If you are using the ElasticSearch sink in NuGet anything that results in a mapping conflict will be lost. Also Serilog does not handle Cyclical relationships so this will result in depth limiter selflog errors. There is a project that attempts to address this by destructuring into dictionaries and passing this to Serilog but you will still wind up with messy logs and mapping exceptions.

    Serilog: https://nblumhardt.com/2016/02/serilog-tip-dont-serialize-arbitrary-objects/

    I've found it best to be specific about logging exception properties based on what you find useful in the exception.

提交回复
热议问题