我有一个启用了日志的MSMQ。而且由于我们每天收到超过1000条消息,因此我想清除日志以仅保留最近2天的消息。因此,我想阅读所有消息并对照“当前日期-2天”检查其SentTime属性。但是此刻该程序将停止,因为不会提供Property SentTime。

错误:“ PropertyFilter设置不正确”

代码:

class Program {

    static void Main(string[] args) {

        string queueName = ".\\private$\\TEST;journal";

        MessageQueue msgQueue = new MessageQueue(queueName);
        Message[] messages = msgQueue.GetAllMessages();

        try{

            foreach (Message msg in messages){
                //if(msg.SentTime < DateTime.Today.AddDays(-2)){
                    Console.WriteLine(msg.SentTime);
                //}
            }

        }catch (Exception e){

            Console.WriteLine(e.Message);

        }

        Console.Read();

    }

}


为什么我无法访问该物业?
谁能帮忙?
非常感谢!

最佳答案

您可以使用

msgQueue.MessageReadPropertyFilter.SetAll();


并将所有过滤器属性设置为true。

10-07 15:32