serilog - How can I add a named property that is not part of the message template? -
in cases, add contextual information message (for instance authenticated user), without having include in message template.
i accomplish :
logger.information("doing stuff {foo} thing {bar}. {user}", foo, bar, user) but without {user} in template.
i know logcontext seems overkill when adding contextual information 1 event.
i know can use low-level api logger.write(logevent evnt) control properties included, seems bit code trying accomplish.
i'm pretty sure there short , elegant way super obvious, haven't found :)
update :
i found out afterwards question more or less similar : add custom properties serilog
i figure out on own!
you can use fluent method .forcontext(propertyname, propertyvalue) on single call 1 of .logxxx() methods.
for instance :
logger.forcontext("user", user) .information("doing stuff {foo} thing {bar}", foo, bar) the property added event apply event, , no longer present on next call logger.logxxx() method
update
the article nicholas blumhardt explains quite : context , correlation – structured logging concepts in .net (5)
Comments
Post a Comment