There are loads of connection pool events that you can subscribe to which might help you. These are:
- ConnectionPoolCheckingOutConnectionEvent
- ConnectionPoolCheckedOutConnectionEvent
- ConnectionPoolCheckingOutConnectionFailedEvent
- ConnectionPoolCheckingInConnectionEvent
- ConnectionPoolCheckedInConnectionEvent
- ConnectionPoolAddingConnectionEvent
- ConnectionPoolAddedConnectionEvent
- ConnectionPoolOpeningEvent
- ConnectionPoolOpenedEvent
- ConnectionPoolClosingEvent
- ConnectionPoolClosedEvent
- ConnectionPoolClearingEvent
- ConnectionPoolClearedEvent
- ConnectionCreatedEvent
You can subscribe to these when you setup the MongoClient
var mongoClientSettings = MongoClientSettings.FromUrl(new MongoUrl("mongodb://localhost"));
mongoClientSettings.ClusterConfigurator = clusterConfigurator =>
{
clusterConfigurator.Subscribe<ConnectionPoolCheckingOutConnectionEvent>(e =>
{
});
};
var mongoClient = new MongoClient(mongoClientSettings);