the following code wraps call serilog logging using statement decorate call. wish ensure type ilogger can passed in action. _logger implements ilogger.
public class auditlogger : iauditlogger { public void audit(action logger) { using (logcontext.pushproperty("eventtype", "audit")) { logger.invoke(); } } } _auditlogger.audit(()=>_logger.information("edit user {userid}",id)); //_auditlogger implements ilogger
if there smarter approach i'm doing feel free offer up.
you aren't "passing in" ilogger, you're passing in lambda can random thing.
you like:
audit(ilogger logger, action<ilogger> action) { action(logger); } audit(_logger, x => x.information(...));
or if auditlogger constructed independently, can pass in _logger constructor , action method.
Comments
Post a Comment