How to Provide Logger with Custom Parameters/Attributes?

I’m using NLog as my logging provider. I’d like to set custom attributes, for example, “modulename”, and “userref”, so in my web.config I could specify these:


And, when logging, I could assign the custom attributes, and have them available for rendering in NLog. In this example, both the message, and the exception, have the attributes available.

customAttributes[“modulename”] = “Module A”;
customAttributes[“userref”] = “User A”;
logger.Error(“Some message”, customAttributes, ex);

Is the best approach for me to extend this somehow? Or, is there a way to provide custom attributes that I’m missing?

ServiceStack’s generic Logging abstraction does not accept custom attributes. For NLog’s specific features you’d need to use their logger directly.

var log = NLog.LogManager.GetLogger(typeName);

FYI these are the wrapper classes for ServiceStack.Logging.NLog adapter.