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 CacheFailureWithInstrumentationDisabledDoesNotWriteToEventLog() { ICachingInstrumentationProvider provider = new CachingInstrumentationProvider(instanceName, false, false, formatter); Exception exception = new Exception(exceptionMessage); using (var eventLog = new EventLogTracker(GetEventLog())) { provider.FireCacheFailed(errorMessage, exception); Assert.AreEqual(0, eventLog.NewEntries().Count()); } }
public void ShouldLogOnlyToCategoriesGivenInConfig() { using (var configSource = new FileConfigurationSource("LogCallHandler.config", false)) { using (var eventLog = new EventLogTracker("Application")) { using (var injector = new PolicyInjector(configSource)) { LoggingTarget target = injector.Create<LoggingTarget>(); target.DoSomething(1, "two", 3.0); } Assert.AreEqual(1, eventLog.NewEntries().Select(le => le.Category == "Default Category").Count()); } } }
public void DefaultLoggerWritesToEventLog() { DefaultCachingEventLogger logger = new DefaultCachingEventLogger(true); ConfigurationErrorsException exception = new ConfigurationErrorsException(exceptionMessage); using (var eventLog = new EventLogTracker(GetEventLog())) { logger.LogConfigurationError(instanceName, exception); var newEntries = from entry in eventLog.NewEntries() where entry.Message.IndexOf(exceptionMessage) > -1 select entry; Assert.AreEqual(1, newEntries.ToList().Count); } }
public void CacheCallbackFailureWithInstrumentationDisabledDoesNotWriteToEventLog() { ICachingInstrumentationProvider provider = new CachingInstrumentationProvider(instanceName, false, false, formatter); Exception exception = new Exception(exceptionMessage); using (var eventLog = new EventLogTracker(GetEventLog())) { provider.FireCacheCallbackFailed(errorMessage, exception); var newEntries = from entry in eventLog.NewEntries() where entry.Message.IndexOf(exceptionMessage) > -1 select entry; Assert.AreEqual(0, newEntries.Count()); } }
public void ShouldCombineWithPoliciesDefinedInConfiguration() { using (var configSource = new FileConfigurationSource("CombinesWithConfig.config", false)) { using (var eventLog = new EventLogTracker("Application")) { using (var injector = new PolicyInjector(configSource)) { var typeWhichUndergoesLoggingOnMethodCall = injector.Create<TypeWhichUndergoesAttributeBasedLogging>(); typeWhichUndergoesLoggingOnMethodCall.TestMethod(); typeWhichUndergoesLoggingOnMethodCall.MyProperty = "hello"; } Assert.AreEqual(2, eventLog.NewEntries().Select(le => le.Message.Contains("This is before the call")). Count()); } } }
public void InvalidMessageIsLoggedAndRemovedFromTheQueue() { clientListener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 0, "not a log entry"); using (var eventLog = new EventLogTracker(GetEventLog())) { msmqDistributor.CheckForMessages(); Assert.AreEqual(1, eventLog.NewEntries().Count(ev => EventIsFromLogger(ev, eventLogger))); } Assert.IsTrue(IsQueueEmpty()); }
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 EventLogWrittenWhenCreatingUndefinedPolicy() { using (var tracker = new EventLogTracker("Application")) { try { ExceptionPolicy.HandleException(new Exception(), "ThisIsAnUnknownKey"); } catch (ActivationException) { var entries = from entry in tracker.NewEntries() where entry.Source == "Enterprise Library ExceptionHandling" && entry.Message.Contains("ThisIsAnUnknownKey") select entry; Assert.AreEqual(1, entries.Count()); } } }