As you may know, MSMQ has internal error logging enabled by default and outputs to a file called MSMQLOG.BIN in the %windir%\debug directory.
The file, as the extension hints at, is in a binary format (unlike MSMQ 2.0) and so cannot be read by simply opening it in Notepad. Instead the file has to be sent to Microsoft support services to be formatted and analysed. Due to the nature of the content (internal function references, etc.), you may not get to see the text output.
The logging can be enabled or disabled using the MQTRACE script which you can download from my blog. This allows some basic control, such as being able to raise the default logging level from "Error" (just logging errors) to "Information" (logging everything).
For example, to enable Information level logging you would carry out the following steps:
and when you have finished:
to set logging back to the default.
Note that the size of the MSMQLOG.BIN file is limited to 4MB. Once the file is full, it starts to overwrite itself in a circular fashion (when full, writing from the end, back to the start and on through the file again). This isn't too much of a problem when you are logging just errors but full logging can fill the file pretty quickly. This can result in the information you want to capture being lost before you have time to disable logging.
MQTRACE uses a program called LOGMAN.EXE to set the way MSMQ performs logging. This program has a lot of options you can pass it as parameters but we only need a few. For example, to set a 50MB log file:
logman create trace msmq -max 50 –f bincirc -o C:\WINDOWS\Debug\msmqlog.bin –ets
which can be explained as follows:
You should see the following output if the changes were successful:
C:\temp>logman create trace msmq -max 50 -f bincirc -o C:\WINDOWS\Debug\msmqlog.bin -ets Name: MSMQAge Limit: 15Buffer Size: 8Buffers Written: 1Clock Type: SystemEvents Lost: 0Flush Timer: 0Buffers Free: 2Buffers Lost: 0File Mode: CircularFile Name: C:\WINDOWS\Debug\msmqlog.binLogger Id: 3Logger Thread Id: 2780Maximum Buffers: 25Maximum File Size: 50Minimum Buffers: 3Number of buffers: 3Real Time Buffers Lost: 0
C:\temp>logman create trace msmq -max 50 -f bincirc -o C:\WINDOWS\Debug\msmqlog.bin -ets
Name: MSMQAge Limit: 15Buffer Size: 8Buffers Written: 1Clock Type: SystemEvents Lost: 0Flush Timer: 0Buffers Free: 2Buffers Lost: 0File Mode: CircularFile Name: C:\WINDOWS\Debug\msmqlog.binLogger Id: 3Logger Thread Id: 2780Maximum Buffers: 25Maximum File Size: 50Minimum Buffers: 3Number of buffers: 3Real Time Buffers Lost: 0
As I mentioned, though, MQTRACE.CMD uses LOGMAN so as soon as you run the script, any changes you made manually at the command prompt will have been overvritten. If we look in the script using Notepad, we find the (most important) LOGMAN command is:
logman %tracecommand% %log_session_name% %mqRealTime% -pf %msmqtracecfgfile% %tracefilepathcommand% %tracefilemodeoptions% -ets
which makes use of memory variables defined elsewhere in the file.
Near the beginning of the script, you will find:
set mqBinaryLog=%windir%\debug\msmqlog.binset mqTextLog=%windir%\debug\msmqlog.txtset log_session_name=msmqset msmqtracecfgfile=%windir%\debug\msmqtrc.iniset msmqtracesessionlog=%windir%\debug\msmqtrc.logset loggingrunning=set mqRealTime=set tracecommand=startset tracefilemodeoptions=-f bincirc -max 4set tracefilepathcommand=-o %mqBinaryLog%set IsWinXP=0set TmpVerFile=%tmp%\osver.txt
The final LOGMAN command generated this way is pretty similar to the one I detailed above. You may want to edit MQTRACE.CMD and set the variables directly so you can, for example, set the "-max" parameter to 50.
Notes