We have a custom logging implementation for NServiceBus that adds properties to logs; it does this by storing it in a IDictionary object that is managed by an AsyncLocal class.
When we add:
NServiceBus.Logging.LogManager.Use<OurCustomFactory>();
To the service we run into The given key was not present in the dictionary
, Object reference not set to an instance of an object
and Unable to cast object of type 'System.String' to type 'System.Object[]'
exceptions; this, I think, is due to race conditions of different threads accessing and changing our Dictionary.
I'm at at ends with the code; I tried wrapping it in locks and that didn't work, I've tried playing around with the async/await code to ensure nothing is left being awaited; I've even removed some of the code that adds the properties but this still has an effect.
Any ideas?