protected override void WriteTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message, Guid?relatedActivityId, object[] data)
        {
            var  traceTime  = TraceFormatter.FormatUniversalTime(eventCache);
            int  maxPerHour = MaxTracesPerHour;
            bool sendEmail  = false;

            if (maxPerHour > 0)
            {
                lock (floodLimitLock)
                {
                    if (traceTime > floodLimitReset)
                    {
                        // start a new flood limit
                        floodLimitReset     = traceTime.Add(floodLimitWindow);
                        floodNumberOfTraces = 0;
                    }
                    if (floodNumberOfTraces < maxPerHour)
                    {
                        floodNumberOfTraces++;
                        sendEmail = true;
                    }
                }
            }
            else
            {
                sendEmail = true;
            }

            if (sendEmail)
            {
                string subject = traceFormatter.Format(SubjectTemplate, this, eventCache, source,
                                                       eventType, id, message, relatedActivityId, data);

                string body = traceFormatter.Format(BodyTemplate, this, eventCache, source, eventType, id,
                                                    message, relatedActivityId, data);

                // Use hidden/undocumented attribute to switch versions (for testing)
                if (Attributes["poolVersion"] == "B")
                {
                    SmtpWorkerPoolB.BeginSend(FromAddress, ToAddress, subject, body, null, null);
                    return;
                }
                SmtpWorkerPoolC.BeginSend(FromAddress, ToAddress, subject, body, null, null);
            }
            else
            {
                Debug.WriteLine("Dropped message due to flood protection.");
            }
        }
        private void InternalSend(bool waitForComplete)
        {
            StringBuilder bufferToSend;
            string        headerToSend;
            string        subjectToSend;

            lock (bufferLock)
            {
                bufferToSend  = this.eventMessagesBuffer;
                headerToSend  = this.eventMessagesHeader;
                subjectToSend = this.eventMessagesSubject;
                if (eventMessagesBuffer.Length > 0)
                {
                    eventMessagesBuffer  = new StringBuilder(100000);
                    eventMessagesHeader  = null;
                    eventMessagesSubject = null;
                }
            }

            if (bufferToSend.Length > 0)
            {
                string body = headerToSend + Environment.NewLine + bufferToSend.ToString();

                // Use hidden/undocumented attribute to switch versions (for testing)
                if (Attributes["poolVersion"] == "B")
                {
                    var asyncResult = SmtpWorkerPoolB.BeginSend(FromAddress, ToAddress, subjectToSend, body, null, null);
                    if (waitForComplete)
                    {
                        SmtpWorkerPoolB.EndSend(asyncResult);
                    }
                }
                else // default
                {
                    var asyncResult = SmtpWorkerPoolC.BeginSend(FromAddress, ToAddress, subjectToSend, body, null, null);
                    if (waitForComplete)
                    {
                        SmtpWorkerPoolC.EndSend(asyncResult);
                    }
                }
            }
        }