Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="appendText"></param>
        /// <param name="eventId"></param>
        /// <param name="eventReference"></param>
        /// <param name="entryType"></param>
        /// <param name="enumPriority"></param>
        public void Write(string message, bool appendText, int eventId, long eventReference,
                          System.Diagnostics.EventLogEntryType entryType, enumEventPriority enumPriority)
        {
            string referencedMsg = string.Empty;

            referencedMsg = string.Format("Event Reference {0}: {1}{2}"
                                          , eventReference
                                          , Environment.NewLine
                                          , message);

            _msmqLogger.Write(referencedMsg);
        }
        public void WritingMessageSendsSameMessageToMsmq()
        {
            ILogFormatter     formatter = new BinaryLogFormatter();
            MsmqTraceListener listener  =
                new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, formatter, MessagePriority.Low, true,
                                      MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue,
                                      false, false, false, MsmqTraceListenerData.DefaultTransactionType, new MockMsmqInterfaceFactory());

            listener.Write("message");

            Message message = MockMsmqInterface.Instance.message;

            Assert.IsNotNull(message);
            Assert.IsNotNull(message.Body);
            Assert.AreEqual(typeof(string), message.Body.GetType());
            Assert.AreEqual("message", message.Body);
        }
        public void IllFormattedMessageWritesInEventLog()
        {
            MsmqReceiverTestWrapper testSync        = new MsmqReceiverTestWrapper(logWriter, CommonUtil.MessageQueuePath, eventLogger);
            MsmqTraceListener       mqTracelistener = new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, new BinaryLogFormatter(),
                                                                            MessagePriority.Normal, false, new TimeSpan(0, 1, 0), new TimeSpan(0, 1, 0),
                                                                            false, true, false, MessageQueueTransactionType.None);

            mqTracelistener.Write("this is a plain trace message");
            try
            {
                testSync.CheckForMessages();
            }
            catch (LoggingException) { }

            string eventlogEntry = CommonUtil.GetLastEventLogEntry();

            Assert.IsTrue(-1 != eventlogEntry.IndexOf("Unable to deserialize message"));
        }
        public void WritingMessageSendsSameMessageToMsmq()
        {
            ILogFormatter formatter = new BinaryLogFormatter();
            MsmqTraceListener listener =
                    new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, formatter, MessagePriority.Low, true,
                                          MsmqTraceListenerData.DefaultTimeToBeReceived, MsmqTraceListenerData.DefaultTimeToReachQueue,
                                          false, false, false, MsmqTraceListenerData.DefaultTransactionType, new MockMsmqInterfaceFactory());

            listener.Write("message");

            Message message = MockMsmqInterface.Instance.message;
            Assert.IsNotNull(message);
            Assert.IsNotNull(message.Body);
            Assert.AreEqual(typeof(string), message.Body.GetType());
            Assert.AreEqual("message", message.Body);
        }