Trouble using Nlog for logging


I’m stuck having to work with classic asp.

I have a com interop dll working against a .NET SDK

I have the following code in my dll:

		Common.Logging.LogManager.Adapter = new Common.Logging.NLog.NLogLoggerFactoryAdapter((Common.Logging.Configuration.NameValueCollection)null);

		LoggingConfiguration config = new LoggingConfiguration();
		config.AddTarget("file", m_fileLog);

		var rule = new LoggingRule("*", m_minLogLevel, m_fileLog);

		LogManager.Configuration = config;

I’ve made sure that the filename and logLevel params are getting through from the asp.
Also when I try to use Log.Trace(“hello”) in my interop .net code It’s working fine.
But no couchbase data is written to the logs.

(the reason I need the logs is to try to debug ‘NodeUnavailableException’ exceptions i’m getting sometimes when trying to get a key when I have about 20-50 concurrent connections from the same machine.

Does anyone have any idea why I’m having issue with logging or with the exception? (I’m on .net 4.5)

I’m not certain, but I think the issue is that you’re configuring NLog programatically. I think you need to configure it using XML and reference that in the adapter, using either INLINE or FILE. Alternatively, you can also put the adapter configuration in XML as well, and remove all programatic configuration.

I don’t think so.

Nlog is working when I configure it progamatically. just not in couchbase sdk.
Besides, I can’t configure it in web.config because i’m using asp and not The configurations won’t be loaded this way.


I realize that it’s working elsewhere, but looking at the NLogLoggerFactoryAdapter it appears to me that it uses it’s own alternative configuration, not what you’ve loaded into the NLog LogManager.Configuration.

If you’re using ASP, you should be able to use the configType “FILE” option to load a separate nlog.config file (path in the “configFile” option). Something like this:

Common.Logging.LogManager.Adapter =
    new Common.Logging.NLog.NLogLoggerFactoryAdapter(new Common.Logging.Configuration.NameValueCollection() {
        {"configType", "FILE"},
        {"configFile", "nlog.config"}

Like I said, I’m not 100% sure on this, but worth a try.

It didn’t work, but I think I may have found the answer.

I’m using Nlog 4.5
When I tested it in my interop I used the Nlog Trace/Debug/Error/Info methods and it worked.

Couchbase are using Common.Logging, and apparently it’s Nlog adapter library hasn’t been updated to support Nlog 4.5

So many hours…

@alon.schachter -

Glad you found a solution. This sounds like something we need to address?


There’s also an issue with the version of Common.Logging.
SDK is using Common.Logging 3.3.1
Even if i wanted to use the most recent version that Common.Logging.Nlog library supports, which is 4.4.1 I need to update it to Common.Logging 3.4.1. But your SDK doesn’t support that version. It throws an exception.

So right now the only thing possible is to use Common.Logging 3.3.1 + Common.Logging.Nlog41 v3.3.1 against Nlog 4.1.2

Dependency version changes are independent of the SDK :slight_smile: That being said, I created a Jira ticket to update the Common.Logging dependency to the latest for SDK v2.6.0.