Search code examples
c#nlogcommon.loggingstructured-logging

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?


Solution

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