What method is called during Ilogger conversion of structured logging arguments to string?

Viewed 61

I have an object that I want to pass to logging (default built-in logging to console, no libraries used) as argument like this:

logger.LogDebug("Executing MongoDB command: {Command}", command);

What I was expecting is that the result will be a call to command.ToString(), but the result of this call differs from the actual ToString() call.

P.S. The object in question is BsonDocument from MongoDB drivers if this has any importance.

P.P.S. I have compared to the interpolated string result as well and it is different (it seems it returns ToString() as I expected):

logger.LogDebug($"Executing MongoDB command: {command}");
1 Answers
Related