3
votes

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?

2
Think you are waiting for this issue: github.com/net-commons/common-logging/issues/159 (Sadly enough fixing this will be a "breaking" change as Common-Logging for some reason tries to perform the parsing and formatting, instead of letting the logging framework do the job). SerilogLogger performs a hack to work-around the restrictions of the Common-Logging-Framework, so can work with structured-logging. - Rolf Kristensen
It seems so indeed.. I am now trying LibLog as we speak. I have structured logging working with the LibLog/NLog combination, only having problems displaying the info I pass in via OpenMappedContext. - Michel van Engelen

2 Answers

2
votes

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

0
votes

Checkout serilog to have structured logging. If your requirements is to use NLog, serilog also has a sink to NLog.