/// <summary> /// Initialize a new instance of the <see cref="MsmqListener"/>. /// </summary> /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param> /// <param name="timerInterval">Interval to check for new messages.</param> /// <param name="msmqPath">The name of the queue to get messages from.</param> public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath) { this.distributorService = distributorService; this.QueueTimerInterval = timerInterval; this.eventLogger = distributorService.EventLogger; this.logDistributor = new MsmqLogDistributor(msmqPath, this.eventLogger); }
/// <summary> /// Initialize a new instance of the <see cref="MsmqListener"/>. /// </summary> /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param> /// <param name="timerInterval">Interval to check for new messages.</param> /// <param name="msmqPath">The name of the queue to get messages from.</param> public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath) { this.distributorService = distributorService; this.QueueTimerInterval = timerInterval; this.eventLogger = distributorService.EventLogger; this.logDistributor = new MsmqLogDistributor(EnterpriseLibraryFactory.BuildUp<LogWriter>(), msmqPath, this.eventLogger); }
/// <summary> /// Initialize a new instance of the <see cref="MsmqListener"/>. /// </summary> /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param> /// <param name="timerInterval">Interval to check for new messages.</param> /// <param name="msmqPath">The name of the queue to get messages from.</param> public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath) { this.distributorService = distributorService; this.QueueTimerInterval = timerInterval; this.eventLogger = distributorService.EventLogger; this.logDistributor = new MsmqLogDistributor(EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(), msmqPath, this.eventLogger); }
public void ServiceStoppedWritesToEventLog() { DistributorEventLogger logger = new DistributorEventLogger(); using (var eventLog = new EventLogTracker(GetEventLog())) { logger.LogServiceStopped(); Assert.AreEqual(1, eventLog.NewEntries().Count(ev => EventIsFromLogger(ev, logger))); } }
public void ServiceFailureWithExceptionWritesToEventLog() { DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName); using (EventLog eventLog = GetEventLog()) { int eventCount = eventLog.Entries.Count; logger.LogServiceFailure(message, GetException(), TraceEventType.Error); Assert.AreEqual(eventCount + 1, eventLog.Entries.Count); } }
public void ServiceStoppedWritesToEventLog() { DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName); using (EventLog eventLog = GetEventLog()) { int eventCount = eventLog.Entries.Count; logger.LogServiceStopped(); Assert.AreEqual(eventCount + 1, eventLog.Entries.Count); } }
public void ServiceStartedFiresWmiEvent() { DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName); using (WmiEventWatcher eventListener = new WmiEventWatcher(1)) { logger.LogServiceStarted(); eventListener.WaitForEvents(); Assert.AreEqual(1, eventListener.EventsReceived.Count); Assert.AreEqual("DistributorServiceLifecycleEvent", eventListener.EventsReceived[0].ClassPath.ClassName); Assert.AreEqual(true, eventListener.EventsReceived[0].GetPropertyValue("Started")); } }
public void ServiceFailureWithExceptionFiresWmiEvent() { DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName); using (WmiEventWatcher eventListener = new WmiEventWatcher(1)) { logger.LogServiceFailure(message, GetException(), TraceEventType.Error); eventListener.WaitForEvents(); Assert.AreEqual(1, eventListener.EventsReceived.Count); Assert.AreEqual("DistributorServiceFailureEvent", eventListener.EventsReceived[0].ClassPath.ClassName); Assert.IsTrue(((string)eventListener.EventsReceived[0].GetPropertyValue("FailureMessage")).StartsWith(message)); } }
public void SetUp() { CommonUtil.DeletePrivateTestQ(); CreateQueueForTesting(); clientSource = new LogSource("unnamed", SourceLevels.All); clientSource.Listeners.Add( 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)); LogSource distributorSource = new LogSource("unnamed", SourceLevels.All); distributorSource.Listeners.Add(new MockTraceListener()); Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>(); logWriter = new LogWriterImpl(new List<ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "default", false, false); eventLogger = new DistributorEventLogger(); msmqDistributor = new MsmqLogDistributor(logWriter, CommonUtil.MessageQueuePath, eventLogger); msmqDistributor.StopReceiving = false; }
/// <summary/> /// <exclude/> /// <devdoc> /// Initialization of the service. Start the queue listener and write status to event log. /// </devdoc> public void InitializeComponent() { try { // Use the default settings for log name and application name. // This is done to ensure the windows service starts correctly. this.ApplicationName = DefaultApplicationName; this.eventLogger = new DistributorEventLogger(); this.eventLogger.AddMessage(Resources.InitializeComponentStartedMessage, Resources.InitializeComponentStarted); this.status = ServiceStatus.OK; IConfigurationSource configurationSource = GetConfigurationSource(); MsmqDistributorSettings distributorSettings = MsmqDistributorSettings.GetSettings(configurationSource); if (distributorSettings == null) { throw new ConfigurationErrorsException(string.Format( Resources.Culture, Resources.ExceptionCouldNotFindConfigurationSection, MsmqDistributorSettings.SectionName)); } this.queueListener = CreateListener(this, distributorSettings.QueueTimerInterval, distributorSettings.MsmqPath); this.ApplicationName = this.ServiceName; this.ApplicationName = distributorSettings.ServiceName; this.eventLogger.AddMessage(NameTag, this.ApplicationName); this.eventLogger.ApplicationName = this.ApplicationName; this.eventLogger.AddMessage(Resources.InitializeComponentCompletedMessage, Resources.InitializeComponentCompleted); } catch (LoggingException loggingException) { this.eventLogger.LogServiceFailure( string.Format(Resources.Culture, Resources.ServiceStartError, this.ApplicationName), loggingException, TraceEventType.Error); throw; } catch (Exception ex) { this.eventLogger.LogServiceFailure( string.Format(Resources.Culture, Resources.ServiceStartError, this.ApplicationName), ex, TraceEventType.Error); throw new LoggingException(Resources.ErrorInitializingService, ex); } }
private static bool EventIsFromLogger(EventLogEntry entry, DistributorEventLogger logger) { return entry.Source == logger.EventSource; }
public MsmqReceiverTestWrapper(LogWriter logWriter, string msmqPath, DistributorEventLogger eventLogger) : base(logWriter, msmqPath, eventLogger) { }
/// <summary> /// Setup the queue and the formatter of the messages. /// </summary> public MsmqLogDistributor(LogWriter logWriter, string msmqPath, DistributorEventLogger eventLogger) { this.logWriter = logWriter; this.msmqPath = msmqPath; this.eventLogger = eventLogger; }
/// <summary> /// Setup the queue and the formatter of the messages. /// </summary> public MsmqLogDistributor(string msmqPath, DistributorEventLogger eventLogger) { this.msmqPath = msmqPath; this.eventLogger = eventLogger; }
public void ServiceFailureWithoutExceptionWritesToEventLog() { DistributorEventLogger logger = new DistributorEventLogger(TestEventSource); using (var eventLog = new EventLogTracker(GetEventLog())) { logger.LogServiceFailure(message, null, TraceEventType.Error); Assert.AreEqual(1, eventLog.NewEntries().Count(ev => EventIsFromLogger(ev, logger))); } }
public void CanCreateDistributorEventLogger() { DistributorEventLogger logger = new DistributorEventLogger(); }
public MsmqReceiverTestWrapper(string msmqPath, DistributorEventLogger eventLogger) : base(msmqPath, eventLogger) { }
public SanityCheck(DistributorService distributorService) { this.eventLogger = distributorService.EventLogger; this.distributorService = distributorService; }
public void CanCreateDistributorEventLogger() { DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName); }