private static void UpdateDeliveryExceptionCallstackRecords(MessageStatus messageStatus, int callstacksPerBucket, StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord occurrenceRecord) { if (callstacksPerBucket > 0) { string key = messageStatus.Exception.ToString(); lock (StoreDriverDeliveryDiagnostics.exceptionDeliveryCallstackRecords) { Dictionary <string, StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord> dictionary; if (!StoreDriverDeliveryDiagnostics.exceptionDeliveryCallstackRecords.TryGetValue(messageStatus.Action, out dictionary)) { dictionary = new Dictionary <string, StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord>(callstacksPerBucket); StoreDriverDeliveryDiagnostics.exceptionDeliveryCallstackRecords[messageStatus.Action] = dictionary; } StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord deliveryOccurrenceRecord; if (!dictionary.TryGetValue(key, out deliveryOccurrenceRecord) && dictionary.Count == callstacksPerBucket) { DateTime t = DateTime.MaxValue; string key2 = null; foreach (KeyValuePair <string, StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord> keyValuePair in dictionary) { if (keyValuePair.Value.Timestamp < t) { t = keyValuePair.Value.Timestamp; key2 = keyValuePair.Key; } } dictionary.Remove(key2); } dictionary[key] = occurrenceRecord; } } }
internal static void UpdateDeliveryExceptionStatisticRecords(MessageStatus messageStatus, int lastOccurrencesPerException, int callstacksPerBucket, MailItemDeliver mailItemDeliver) { StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord deliveryOccurrenceRecord = new StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord(DateTime.UtcNow, mailItemDeliver.MbxTransportMailItem.DatabaseName, StoreDriverDelivery.MailboxServerFqdn, mailItemDeliver.MbxTransportMailItem.InternetMessageId, mailItemDeliver.Recipient.Email, mailItemDeliver.RecipientStartTime, mailItemDeliver.SessionId, mailItemDeliver.MbxTransportMailItem.MimeSize, mailItemDeliver.MbxTransportMailItem.MailItemRecipientCount, mailItemDeliver.MbxTransportMailItem.MimeSender, mailItemDeliver.MbxTransportMailItem.RoutingTimeStamp, mailItemDeliver.Stage); if (lastOccurrencesPerException > 0) { string key = StoreDriverDeliveryDiagnostics.GenerateExceptionKey(messageStatus); lock (StoreDriverDeliveryDiagnostics.deliveryExceptionStatisticRecords) { StoreDriverDeliveryDiagnostics.ExceptionStatisticRecord <StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord> value; if (!StoreDriverDeliveryDiagnostics.deliveryExceptionStatisticRecords.TryGetValue(key, out value)) { value = default(StoreDriverDeliveryDiagnostics.ExceptionStatisticRecord <StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord>); value.LastOccurrences = new Queue <StoreDriverDeliveryDiagnostics.DeliveryOccurrenceRecord>(lastOccurrencesPerException); } if (value.LastOccurrences.Count == lastOccurrencesPerException) { value.LastOccurrences.Dequeue(); } value.LastOccurrences.Enqueue(deliveryOccurrenceRecord); value.CountSinceServiceStart++; StoreDriverDeliveryDiagnostics.deliveryExceptionStatisticRecords[key] = value; } } StoreDriverDeliveryDiagnostics.UpdateDeliveryExceptionCallstackRecords(messageStatus, callstacksPerBucket, deliveryOccurrenceRecord); }