CaptiveAire/Common.Logging.Serilog — pull request #3 by mperdeck (2014-06-29 09:43:13+00:00)
Title: Allow structured objects to be sent to common logger as JSON strings

After trying to log structured objects (rather than strings) via other Common.Logging adapters (common.logging.nlog, common.logging.elmah), I found that these simply log the name of the object, discarding all information in the object. So anyone logging via Common.Logging has to serialize their objects into strings before logging them.

However, I would still like to log objects in a structured manner when common.logging.serilog is used, because that is the whole point of serilog. So the code change in this pull request checks whether the log message is a string and also a JSON object, and if so deserializes it so serilog can log it in a structured manner.

This way, someone who has been logging objects as strings can switch to structured logging with common.logging.serilog through configuration, without changing their code. This will make adoption of structured logging much easier when dealing with big code bases.

My pull request only deals with objects serialized to JSON. If an object has been serialized to XML, it will still be logged as a (destructured) string.