3

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?

Michel van Engelen
  • 2,791
  • 2
  • 29
  • 45
  • 2
    Think you are waiting for this issue: https://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 Jan 21 '19 at 18:13
  • 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 Jan 22 '19 at 08:00

2 Answers2

3

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

Michel van Engelen
  • 2,791
  • 2
  • 29
  • 45
1

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

  • My requirement is to use Common.Logging with structured logging. If there are any good examples of Common.Logging with Serilog, I can try that. I'd be happier when I can get it to work with NLog, so I don't have to reconfigure all my app domains. – Michel van Engelen Jan 21 '19 at 15:40
  • 1
    If it helps, there's example Common.Logging + Serilog info in: https://github.com/CaptiveAire/Common.Logging.Serilog#readme – Nicholas Blumhardt Jan 21 '19 at 21:37