/// <summary> /// /// </summary> private void Start() { _queue = new MessageQueue(QueueName); _queue.ReceiveCompleted += delegate(Object source, ReceiveCompletedEventArgs asyncResult) { try { // End the asynchronous receive operation. Message m = ((MessageQueue)source).EndReceive(asyncResult.AsyncResult); if (Notifiable != null) { string loggingEvent = Encoding.ASCII.GetString(((MemoryStream)m.BodyStream).ToArray()); LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger"); logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName); logMsg.RootLoggerName = QueueName; Notifiable.Notify(logMsg); } if (BulkProcessBackedUpMessages) { Message[] all = ((MessageQueue)source).GetAllMessages(); if (all.Length > 0) { int numberofmessages = all.Length > 1000 ? 1000 : all.Length; LogMessage[] logs = new LogMessage[numberofmessages]; for (int i = 0; i < numberofmessages; i++) { Message thisone = ((MessageQueue)source).Receive(); string loggingEvent = Encoding.ASCII.GetString(((MemoryStream)thisone.BodyStream).ToArray()); LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger"); logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName); logs[i] = logMsg; } Notifiable.Notify(logs); } } ((MessageQueue)source).BeginReceive(); } catch (MessageQueueException) { // Handle sources of MessageQueueException. } }; _queue.BeginReceive(); }