I'm working on a distributed system composed of multiple services (processes) working together orchestrated via message broker (service bus). Some of these service are very time sensitive, so we had the idea of using the bus the propagate exceptions to a service that would be used as a central point to log (to a database/on disk) the exceptions of all other services in order not to create latency in our services because we know sending a message is faster than writing on disk. So using NLog, I create a new target for sending exceptions on bus and redirect all service exception handling to it.
It works fine for basic framework exceptions, but of course some exceptions can be pretty complex objects. When using different libraries, not only are some exception not serializable (ex: IronPython), but more importantly our ExceptionLogger service don't have reference to every external dll used by every other endpoints, so it can't instantiate the typed exception.
Here's a few idea that I had to fix my problem, but none work:
Have the exception logger service reference every dlls used by the other services. In my opinion this is not clean, pretty overkill and still don't handle the case of exceptions that can't even be serialized and passed on the bus.
Creating a custom class that doesn't inherit from exception to pass only the data (as Antony Booth method here: How to serialize an Exception object in C#?). Problem with this is that when I receive an instance of this class on my exception logger endpoint and want to trigger a log, I can't create a new Exception() from it to create a NLog LogEventInfo object.
Transform the specially typed exception to a base native Exception type before sending it on the bus. This way, I lose some information, but I would keep the Message, Stacktrace and the InnerException stack, which is pretty much everything I need. Unfortunately, I did not find a way to do it and don't think it is possible.
That makes me question the relevance of the whole idea, am I simply going into a wrong path?