There is a nice example under "Optimizing applications>Synchronizing Tasks>Queue Message logging". This will do what you want except storing to file.
Waldemar
Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions