You can register a func
but it won’t help with the DTOP.
Could you please clarify where would the data you want to add come from?
Is it something you have access to at some point before calling some business logic?
I suggest simply pushing a scope (which in asp.net core you can do with the logger interface) and adding your DTO:
var dto = _dep.GetDto();
using (logger.BeginScope(dto))
{
// any event raised in this block will include the serialized DTO
}
// Scope is gone, so DTO won't be included anymore