Lock Contention - LogManager.GetLogger

Hello.
We are using Couchbase SDK 2.7.10 targeting net452 framework and we have noticed a high Lock Contention in LogManager.GetLogger method due to LoggerFactory.CreateLogger. Are there any workaround for that?

CreateLogger method
image

Hmmm, this seems like an oversight in our consumption of ILoggerFactory from Microsoft

It appears, based on a quick review, that Microsoft’s assumption is that CreateLogger is generally only called once and that their DI infrastructure is the primary cache of the ILogger instances, which are registered as Singleton. In the Couchbase SDK we’re calling CreateLogger every time on the assumption that Microsoft’s LoggerFactory caching is more performant.

My recommendation would be a code change to cache these loggers internally using a ConcurrentDictionary<string, ILogger> to provide less lock contention.

The other option is to upgrade to the 3.x SDK. I just reviewed that code, and I don’t believe it suffers from this problem. It already uses a ConcurrentDictionary to cache ILogger singletons.

@jmorris do you have any thoughts?

Brant