Beispiel #1
0
        protected void AddMessageAudit(Message msg, string subQueueName = null, Exception ex = null)
        {
            if (!AuditActivity)
            {
                return;
            }

            using (var transaction = new TransactionScope(
                       TransactionScopeOption.Required,
                       new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                var messageAudit = new MessageAudit
                {
                    MessageId      = msg.Id,
                    MessageStatus  = MessageStatus.AwaitingProcessing,
                    CorrelationId  = msg.CorrelationId,
                    QueueName      = null == subQueueName ? QueueName : string.Format("{0};{1}", QueueName, subQueueName),
                    QueuePath      = null == subQueueName ? QueuePath : string.Format("{0};{1}", QueuePath, subQueueName),
                    MessageContent = GetMessageXml(msg)
                };
                var newId = MessageQueueService.CreateMessageAudit(messageAudit);
                if (null != ex)
                {
                    var processingError = new MessageProcessingError
                    {
                        MessageAuditId = newId, Error = ex.Message, StackTrace = ex.StackTrace, TmStamp = DateTime.Now
                    };
                    MessageQueueService.CreateMessageAuditException(processingError);
                }

                transaction.Complete();
            }
        }