-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Symptoms
When the NServiceBus endpoint is used outside of the context of an NServiceBus message handler, NServiceBus log entries are missing for Send, Reply, Publish, Subscribe, and Unsubscribe operations. These log entries may be flushed to the Azure Service Bus logs when the next call is made, if the call is processed by the same running instance of the Azure Function. If the Azure Function host is shut down in between calls, then the log messages are lost.
Who's affected
All users of NServiceBus.AzureFunctions.InProcess.ServiceBus verions 1.0, 1.1, 1.2, and 1.3 are affected.
Root cause
When the user passes in a logger instance we store it in an async local context so that all log entries in the same async context will write to it. The code to set up the logger was in a shared async method. As soon as that method returns, the async context it had written to is cleaned up and the logger instance is no longer referenced. With no logger to write to, subsequent log messages are either discarded (1.0, 1.1, and 1.2) or deferred to the next time when a logger is available (1.3).
This was resolved by moving the code that sets up the logger into the outer async context, ensuring that context persists for the entire operation.