Audit Service that does not require references to all message packages


We are building a series of new services (each in their own solutions). We also have an Audit Service in its own solution. The Audit service currently handles a base class message (that all messages across all of our services extend from). The Audit Service takes a copy of most messages and stores the body and some metadata in Table Storage for a limited time. We use this data as an Audit, also for debugging and to assert our integration tests have passed.
Currently, the Audit service must reference a series of internal nuget packages that contain our various message types from the different services in their separate solutions.

The requirement to reference the latest nuget references means the Audit service can get out of sync. This happens during local development before any message nuget package changes have been committed to nuget. As a result our integration tests can fail when running them locally.

The Audit service doesn’t actually need to deserialize each message it handles to its inherited type, we are only interested in the meta data and the payload - but as a json/string. So it feels like we should be able to achieve what we need without most of the nuget references.
I was wondering if there is a way for me to intercept the audit sending process and transform the outgoing message into a standard MessageEnvelope type message that might look something like this:

public class MessageEnvelope
    public Guid CorrelationId {get;set;}
    public string OriginalPayload {get;set;}
    public string OriginalMessageType{get;set;}
    public DateTime OriginalMessageSentOn{get;set;}
    //some other meta data from original message headers

Then in the Audit Service just have a single nuget reference to the Envelope (that would be a very stable package)

public class MessageEnvelopeHandler : IHandleMessages<MessageEnvelope>
     public async Task Handle(MessageEnvelope message)
         // write payload string and some meta data to table storage

I am also wondering if this is a bad idea!, and there is a better way to solve the problem.

Thanks for your help

Hi @Sean-R,

it looks like you’re replicating the NServiceBus Auditing capability in which case audit messages can be consumed by ServiceControl.

That being said, for your purpose you don’t need to reference message assemblies. You could be leveraging the pipeline or better yet a satellite to access low level messages before they’re being deserialized.

We have extension points for the audit pipeline, but as far as I can tell you cannot alter the audited message.


Hi @mauroservienti, thanks for your reply. Yes it does sound quite similar to ServiceControl, although we do have a few other requirements around it which I think make it useful for us to control that endpoint.

I found this article which describes changing an outbound audit message.

Using this I was able to tweak the audit message and wrap it in an envelope. Then I could remove the nuget message packages from the Audit service.