Problem while reading messages from MSMQ logged by Logging Application Block

Topics: Logging Application Block
Apr 3, 2009 at 10:39 AM

Currently I'm working on EL 4.1 Logging Application Block and MSMQ.
I'm logging messages in a private queue, on my local machine, using Logging Application Block.
The messages are logged smoothly without any issues.
The problem I'm facing is while reading these messages. I wrote a sample application to read the messages from the private queue.



System.Messaging.Message msg = mq.Receive(new TimeSpan(0, 0, 10));

MessageBox.Show(msg.Body as string);


catch (Exception ex)




But throws an error while reading the Body property of the Message object: "Cannot find a formatter capable of reading this message."
I'm logging messages using the MSMQListener. The MSMQ Listener uses the Text Formatter to format the message.
Also the formatters are incompatible. I cannot assign the Text Formatter from Enterprise Library to 
MessageQueue.Formatter  property and vice versa

No Distributor is used here.
I tried installing the Distributor service with reference to the following post:
The service got installed. But whenever I try to start it, the service starts and stops immediately. I've check the event viewer. It does not throw any error.
Also I'm not sure how much the distributor is useful in reading the messages.

My basic aim is to read messages from MSMQ which are logged by Logging Appliction Block.
Is there any way I can read these messages? Can anyone throw some light here? It might be a small thing which I'm missing here.


Apr 3, 2009 at 10:53 AM
Hi, here's a sample code which can successfully read messages from my private queue:

MessageQueue queue = new MessageQueue(@".\Private$\myQueue");
queue.Formatter =
new XmlMessageFormatter(new string[] { "System.String" });
Message message = queue.Receive();

Can you elaborate more on why you can't assign the TextFormatter to the MSMQ Tracelistener?  The distributor service is mainly used for retrieving messages from the queue and logging it to a central destination.  It addresses the issue on having multiple guid-named files when 2 tracelisteners are trying to write to the same file at the same time.  If you're going to use the  MSMQ tracelistener with the Distributor service, you should use the BinaryFormatter.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.



Apr 3, 2009 at 4:17 PM

Hi Sarah,
Thanks a lot. My issue is resolved.

The following line was missing in my code:
queue.Formatter = new XmlMessageFormatter(new string[] { "System.String" });
I had used this method to retrieve message from the queues, in a different application.

Did not think about using this formatter here, since the messages were logged using Text Formatter.

2 small Qs which came up to my mind:

1>     The logger uses Text Formatter and the MessageQueue uses XmlMessageFormatter.

2>     Facing issues with BinaryMessageFormatter

Currently looking into this.

Answer to your question: “Can you elaborate more on why you can't assign the TextFormatter to the MSMQ Tracelistener?”

1> Logging Application Block uses TextFormatter.

The hierarchy is as follows:

TextFormatter -> LogFormatter -> ILogFormatter

2> MessageQueue class has a property – Formatter, which is IMessageFormatter

The hierarchy is as follows:

IMessageFormatter : ICloneable

Thus can’t assign TextFormatter object to IMessageFormatter.

I still have a problem with the Distributor service. Looking into it and in case of any issues will create a new discussion.

Sorry for the delay in my response. The week is at its end and a lot of work to be completed.

Thanks for the response. I got a way to move ahead.