Serilog: Maximum depth of objects destructuring should be controllable per object.

Created on 15 Sep 2015  路  4Comments  路  Source: serilog/serilog

At this time all objects are destructured with the same depth as assigned by .Destructure.ToMaximumDepth(depth). It would be useful to set the destructuring depth per object using either .Destructure.ToMaximumDepth(type, depth) or possibly by using {@Object:depth} format. Ex:

Option 1:

var log = new LoggerConfiguration()
  .Destructure.ToMaximumDepth(typeof(System.Threading.Thread),2);
  .CreateLogger();

Option 2:

var thread = .... // a thread
Log.Information("Started thread {@Thread:2}.", thread);

Thank you.

discussion

All 4 comments

Thanks for the issue; I like both of these and if we're going to consider the feature it probably makes sense to offer both versions.

I'm unsure how much internal churn this would cause - there's probably a good amount of work involved in analyzing the possible implementations for the change, so any input in that direction would be appreciated.

(CC @adamchester who may find this interesting WRT the independent _message templates_ implementation he's created.)

Yes, I do find this suggestion interesting, and it seems useful to me (especially if you are logging types like Thread).

i think depth is better represented in the template with some other format / character ( not :).

While this is still an interesting feature opportunity to pursue I can't see it reaching the top of the priority list in the near future, so I'm tempted to close it and unclutter the tracker. Any thoughts?

Agree @nblumhardt

I think it's currently best if users project/transform Thread (or similar) into some type better suited to logging serialisation.

Was this page helpful?
0 / 5 - 0 ratings