需要批量每周清除系统队列日志。
The correct format for system queues:
FormatName:Direct=os:.\\System$;JOURNAL
I've tested this format on Windows 7 and Windows 2003.
(the dot after os: means the localhost/local computer)
var systemJournalQueue = new MessageQueue("FormatName:Direct=os:.\\System$;JOURNAL");
var systemDeadLetterQueue = new MessageQueue("FormatName:Direct=os:.\\System$;DEADLETTER");
var systemDeadXLetterQueue =new MessageQueue("FormatName:Direct=os:.\\System$;DEADXACT"));
systemJournalQueue.Purge();
or if you want to keep N days of messages you can do this:
private static void PurgeQueues(int archiveAfterHowManyDays, MessageQueue queue)
{
queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(System.String) });
queue.MessageReadPropertyFilter.ArrivedTime = true;
using (MessageEnumerator messageReader = queue.GetMessageEnumerator2())
{
int counter = 0;
while (messageReader.MoveNext())
{
Message m = messageReader.Current;
if (m.ArrivedTime.AddDays(archiveAfterHowManyDays) < DateTime.Now)
{
queue.ReceiveById(m.Id);
counter++;
}
}
}
}
MessageQueue mq = new MessageQueue(".\\Journal$");
mq.Purge();
or
MessageQueue mq = new MessageQueue(".\\myQueue\\Journal$");
mq.Purge();
if its for a queue you created. Make sure the user has the correct permissions. See: http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.aspx
MessageQueue mq = new MessageQueue("DIRECT=OS:computername\SYSTEM$;JOURNAL");
mq.Purge();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.