title: C# ConcurrentBag - How to safely clear on every N objects added
body: <p>I'm implementing a custom logger that logs to AWS CloudWatch and it's is an async logger. The logger works on my WCF service and multiple threads are trying to log at the same time. I've created a thread safe singleton access for the logging to happen but AWS CloudWatch SDK can't send the next log before it finishes sending the current one. </p>
  
  <p>So my idea is to pool the log messages in a ConcurrentBag and once it reaches some N members i will send logs in a batch to CloudWatch (SDK allows this, so it's all good).</p>
  
  <p>The process goes like this : Any thread calls the logger > Logger adds a message to the ConcurrentBag > A sender thread keeps checking the count (or the same one) > If count is >= N send batch log and lock other threads from adding while it's sending > repeat</p>
  
  <p>The process doesn't have to wait for the response to start adding again to the ConcurrentBag. </p>
  
  <p>What would be the best approach to do this? </p>