コード例 #1
0
        public void Log_WithFailingImplementationAndConfiguredFallbackProvider_LogsOriginalFailureToFallbackProvider()
        {
            // Arrange
            var failingProvider = new ThrowingLoggingProvider();

            failingProvider.Initialize("Failing provider name", new NameValueCollection());

            var fallbackProvider = new MemoryLoggingProvider();

            failingProvider.FallbackProvider = fallbackProvider;
            failingProvider.ExceptionToThrowFromLogInternal = new InvalidOperationException();
            var expectedEntry =
                new LogEntry(LoggingEventType.Error,
                             "The event could not be logged with provider 'Failing provider name'.",
                             "CuttingEdge.Logging.Tests.Unit.LoggingProviderBaseTests+ThrowingLoggingProvider",
                             failingProvider.ExceptionToThrowFromLogInternal);

            // Act
            failingProvider.Log("Valid message");

            // Assert
            var loggedEntry = fallbackProvider.GetLoggedEntries().Last();

            AssertHelper.LogEntriesAreEqual(expectedEntry, loggedEntry);
        }
コード例 #2
0
        public void Log_WithFailingImplementationButWithoutConfiguredFallbackProvider_BubblesThrownException()
        {
            // Arrange
            var provider = new ThrowingLoggingProvider();

            provider.ExceptionToThrowFromLogInternal = new InvalidOperationException();

            // Act
            provider.Log("Valid message");
        }
コード例 #3
0
        public void Log_WithFailingImplementationAndConfiguredFallbackProvider_LogsEventToFallbackProvider()
        {
            // Arrange
            var failingProvider  = new ThrowingLoggingProvider();
            var fallbackProvider = new MemoryLoggingProvider();

            failingProvider.FallbackProvider = fallbackProvider;
            failingProvider.ExceptionToThrowFromLogInternal = new InvalidOperationException();
            var entryToLog = new LogEntry(LoggingEventType.Critical, "Valid message", null, null);

            // Act
            ((ILogger)failingProvider).Log(entryToLog);

            // Assert
            var loggedEntry = fallbackProvider.GetLoggedEntries().First();

            Assert.AreEqual(entryToLog, loggedEntry);
        }