Suchiman / SerilogAnalyzer

Roslyn-based analysis for code using the Serilog logging library. Checks for common mistakes and usage problems.
Apache License 2.0
309 stars 29 forks source link

New Rule : detect when passing properties of an anonymous type but forgetting the @ destructuring operator #28

Closed tsimbalar closed 6 years ago

tsimbalar commented 6 years ago

Following the advice from https://nblumhardt.com/2016/02/serilog-tip-dont-serialize-arbitrary-objects/ , it's quite a common pattern to use anonymous classes as a property to enrich a log event. In those case, it's important to remember to add the @ destructuring operator in the message template, or else, the ToString() behavior will be used.

It would be good to detect cases where the user has passed a property of an anonymous type, but forgot to add the @ operator. The code fix would be to add the missing operator in the template.

Suchiman commented 6 years ago

Sounds good 👍 will implement

tsimbalar commented 6 years ago

Thank you !