public override void TestInitialize()
        {
            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            base.TestInitialize();
        }
        public void EntryIsNotWrittenWhenTransactionalQueueAndNoTransaction()
        {
            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            System.Messaging.MessagePriority             messagePriority = System.Messaging.MessagePriority.Lowest;
            System.Messaging.MessageQueueTransactionType trxType         = System.Messaging.MessageQueueTransactionType.Single;
            const string QueuePath = MsmqUtil.MessageQueuePath;

            configurationStart.LogToCategoryNamed(CategoryName)
            .WithOptions
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .Msmq(ListenerName)
            .UseQueue(QueuePath)
            .AsRecoverable()
            .Prioritize(messagePriority)
            .UseDeadLetterQueue()
            .WithTransactionType(trxType)
            .WithTraceOptions(TraceOptions.None)
            .Filter(SourceLevels.Verbose)
            .FormatWith(new FormatterBuilder()
                        .TextFormatterNamed(FormatterName)
                        .UsingTemplate(Template));

            this.SetConfigurationSource();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(LoggingSettings.SectionName));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            LogEntry entry = LogEntryFactory.GetLogEntry(CategoryName, "Test Message");

            this.writer.Write(entry);

            Assert.IsNull(MsmqUtil.GetLogEntryFromQueue());
        }
Beispiel #3
0
        public void EntryIsWrittenWhenMSMQGeneralCategory()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();
            var msmqListener = new MsmqTraceListener("TestMSMQProg", MsmqUtil.MessageQueuePath, new BinaryLogFormatter(),
                                                     MessagePriority.Normal, false, new TimeSpan(0, 1, 0), new TimeSpan(0, 1, 0),
                                                     false, true, false, MessageQueueTransactionType.None);

            msmqListener.Filter = new EventTypeFilter(SourceLevels.All);

            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            LogSource clientSource      = new LogSource("TestMSMQProg", new[] { msmqListener }, SourceLevels.All);
            LogSource distributorSource = new LogSource("TestMSMQProg", new[] { new MockTraceListener() }, SourceLevels.All);

            Dictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>();

            this.writer = new LogWriter(new List <ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "General", false, false);
            Logger.SetLogWriter(this.writer);

            DistributorEventLogger eventLogger     = new DistributorEventLogger();
            MsmqLogDistributor     msmqDistributor = new MsmqLogDistributor(MsmqUtil.MessageQueuePath, eventLogger);

            msmqDistributor.StopReceiving = false;

            LogEntry logEntry = MsmqUtil.GetDefaultLogEntry();

            logEntry.Categories = new string[] { "MockCategoryOne" };
            logEntry.Message    = MsmqUtil.MsgBody;
            logEntry.Severity   = TraceEventType.Information;

            clientSource.TraceData(logEntry.Severity, 1, logEntry);

            msmqDistributor.CheckForMessages();

            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(MsmqUtil.MsgBody, MockTraceListener.LastEntry.Message, "Body");
        }
        public void EntryIsWrittenWhenMaxMSMQTraceListener()
        {
            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration63"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Add("General");

            this.writer.Write(entry);
            this.writer.Dispose();

            string entryText = MsmqUtil.GetLogEntryFromQueue();

            Assert.IsTrue(entryText.Contains(entry.Message));
        }