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 SetUp() { CommonUtil.ValidateMsmqIsRunning(); CommonUtil.DeletePrivateTestQ(); CreateQueueForTesting(); var msmqTraceListener = 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); clientSource = new LogSource("unnamed", new[] { msmqTraceListener }, SourceLevels.All); LogSource distributorSource = new LogSource("unnamed", new[] { new MockTraceListener() }, SourceLevels.All); Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>(); Logger.SetLogWriter(new LogWriter(new List<ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "default", false, false), false); eventLogger = new DistributorEventLogger(); msmqDistributor = new MsmqLogDistributor(CommonUtil.MessageQueuePath, eventLogger); msmqDistributor.StopReceiving = false; }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="MsmqTraceListener"/> based on an instance of <see cref="MsmqTraceListenerData"/>. /// </summary> /// <seealso cref="TraceListenerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="MsmqTraceListenerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="MsmqTraceListener"/>.</returns> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { MsmqTraceListenerData castedObjectConfiguration = (MsmqTraceListenerData)objectConfiguration; ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new MsmqTraceListener( castedObjectConfiguration.Name, castedObjectConfiguration.QueuePath, formatter, castedObjectConfiguration.MessagePriority, castedObjectConfiguration.Recoverable, castedObjectConfiguration.TimeToReachQueue, castedObjectConfiguration.TimeToBeReceived, castedObjectConfiguration.UseAuthentication, castedObjectConfiguration.UseDeadLetterQueue, castedObjectConfiguration.UseEncryption, castedObjectConfiguration.TransactionType); return createdObject; }