0

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?

bendev88
  • 75
  • 6
  • You will need to provide the implementation of your custom logging factory. – Hadi Eskandari Mar 05 '20 at 23:50
  • 1
    So the problem we had is that we had some shared components between the Behaviours and the Handlers; in NServiceBus the Behaviours are always singletons whilst the Handlers aren't. This is why we were getting the above error. – bendev88 Mar 06 '20 at 14:07

0 Answers0