Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structured logging with Common.Logging and NLog

I have the latest version of Common.Logging (3.4.1) and NLog (4.5.11) in my project. Instructions were followed to tie up Common.Logging with NLog in the app.config, and logging now works.

Now I want to have structured logging:

private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

var message = new IDontKnowWhat("A structured message for ClientId {ClientId}", ClientId.ToString());
_logger.Info(message);

The above is pseudo code, I do not know how to construct the message object. And, _logger.InfoFormat seems to work with String.Format, instead of structured logging.

Does Common.Logging provide for structured logging, besides using ThreadVariablesContext/GlobalVariablesContext/NestedThreadVariablesContext?

like image 862
Michel van Engelen Avatar asked Jun 25 '26 13:06

Michel van Engelen


1 Answers

Luckily for me, the Common.Logging development team is currently fixing this: Common.Logging.NLog45 with support for structured logging #176

like image 152
Michel van Engelen Avatar answered Jun 28 '26 03:06

Michel van Engelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!