Using LogWithNameAttribute will Prevent the Property From Being Destructured
bowdens07 opened this issue · 3 comments
Suppose I'm logging a class that has another class inside of it, like so:
public class MessageBase
{
[LogWithName("messageContext")]
public ContextClass Context
}
public class ContextClass
{
public string foo;
public string bar;
public override stringToString() {return "ContextClass ToString Output"}
}
var outputMessageBase = new MessageBase()
logger.logInfo("{@0}", outputMessageBase)
So we see MessageBase has a ContextClass inside of it. If I add the [LogWithName()] attribute over the Context property in MessageBase, serilog will no longer destructure MessageBase's Context property in the output, and will simply output Context's ToString() method. So here's the difference in output:
Without [LogWithName("messageContext")] on MessageBase's Context Property:
{"ContextClass": {"foo":"", "bar":""}}
With [LogWithName("messageContext")] on MessageBase's Context Property:
{"messageContext":"ContextClass ToString Output" }
While this is likely intended behavior, I would like some way to destructure the properties that use the [LogWithName()]. Ideally, I'd like a way for my output to be this:
{"messageContext": {"foo":"", "bar":""}}
Perhaps an argument like a boolean could be passed to the [LogWithName()] attribute, so its API would now be
[LogWithName(string newName, bool destructureObjects=false)]
Note - I am using Serilog.Formatting.Compact.CompactJsonFormatter going into a Console sink, although I don't think that changes the spirit of my question minus some minor details on precisely what the output format looks like. I'm just concerned with destructuring every property that uses destructurama attributes in my output.
Thank you for your time.
This issue was marked as stale since it has not been active for a long time
This issue was marked as stale since it has not been active for a long time