Example #1
0
        public void Constructor_WithNullProvider_ThrowsException()
        {
            // Arrange
            var validThreshold = LoggingEventType.Critical;
            LoggingProviderBase validFallbackProvider = null;

            IEnumerable <LoggingProviderBase> invalidProviderList =
                new LoggingProviderBase[] { new FakeLoggingProvider(), null };

            try
            {
                // Act
                new CompositeLoggingProvider(validThreshold, validFallbackProvider, invalidProviderList);

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));

                var message = ex.Message;

                Assert.IsTrue(message.Contains("providers"), "Message should contain argument name.");
                Assert.IsTrue(message.Contains("collection contains") && message.Contains("null references"),
                              "Message should be descriptive enough. Actual message: " + message);
            }
        }
Example #2
0
        public void Constructor_WithEmptyProviderCollection_ThrowsException()
        {
            // Arrange
            var validThreshold = LoggingEventType.Critical;
            LoggingProviderBase validFallbackProvider = null;

            var invalidProviderList = new LoggingProviderBase[0];

            try
            {
                // Act
                new CompositeLoggingProvider(validThreshold, validFallbackProvider, invalidProviderList);

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));

                var message = ex.Message;

                Assert.IsTrue(message.Contains("providers"), "Message should contain argument name.");
                Assert.IsTrue(message.Contains("Collection should contain") && message.Contains("at least one"),
                              "Message should be descriptive enough. Actual message: " + message);
            }
        }
Example #3
0
        public void Constructor_WithInvalidThreshold_ThrowsException()
        {
            var invalidThreshold = (LoggingEventType)(-1);
            LoggingProviderBase validFallbackProvider = null;
            LoggingProviderBase validProvider         = new FakeLoggingProvider();

            // Act
            new CompositeLoggingProvider(invalidThreshold, validFallbackProvider, validProvider);
        }
Example #4
0
        public void Constructor_WithoutProviders_ThrowsException()
        {
            // Arrange
            var validThreshold = LoggingEventType.Critical;
            LoggingProviderBase validFallbackProvider = null;

            // Act
            new CompositeLoggingProvider(validThreshold, validFallbackProvider, null);
        }
Example #5
0
        public void Constructor_WithValidArguments_Succeeds()
        {
            // Arrange
            var validThreshold = LoggingEventType.Critical;
            LoggingProviderBase validFallbackProvider = null;
            LoggingProviderBase validProvider         = new FakeLoggingProvider();

            // Act
            new CompositeLoggingProvider(validThreshold, validFallbackProvider, validProvider);
        }
Example #6
0
        public void Constructor_WithMultipleProviders_Succeeds()
        {
            // Arrange
            var validThreshold = LoggingEventType.Critical;
            LoggingProviderBase validFallbackProvider = null;
            LoggingProviderBase provider1             = new FakeLoggingProvider();
            LoggingProviderBase provider2             = new FakeLoggingProvider();

            // Act
            new CompositeLoggingProvider(validThreshold, validFallbackProvider, provider1, provider2);
        }
Example #7
0
        /// <summary>Create the specified named logger instance.</summary>
        /// <param name="name">The name of the logger.</param>
        /// <returns>An instance (instances are cached).</returns>
        protected override ILog CreateLogger(string name)
        {
            LoggingProviderBase provider = this.FindProviderByExactName(name);

            if (provider == null)
            {
                provider = this.FindClosestHierarchicalParentProvider(name);

                if (provider == null)
                {
                    provider = this.DefaultProvider;
                }
            }

            return(new CuttingEdgeLogger(provider));
        }
        public void Providers_RequestingAProviderByName_IsCaseInsensitive()
        {
            // Arrange
            LoggingProviderBase expectedProvider = Logger.Provider;
            string lowerCaseProviderName         = expectedProvider.Name.ToLowerInvariant();

            // Act
            LoggingProviderBase sameProvider1 = Logger.Providers[expectedProvider.Name.ToLowerInvariant()];
            LoggingProviderBase sameProvider2 = Logger.Providers[expectedProvider.Name.ToUpperInvariant()];

            // Assert
            Assert.AreEqual(expectedProvider, sameProvider1,
                            "Requesting a provider by name is expected to be case insensitive.");
            Assert.AreEqual(expectedProvider, sameProvider2,
                            "Requesting a provider by name is expected to be case insensitive.");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AspNetSqlLoggingProvider"/> class.
        /// </summary>
        /// <param name="threshold">The <see cref="LoggingEventType"/> logging threshold. The threshold limits
        /// the number of event logged. <see cref="LoggingProviderBase.Threshold">Threshold</see> for more
        /// information.</param>
        /// <param name="configuration">The configuration that initializes this provider.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="fallbackProvider">The optional fallback provider.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="connectionString"/> or the
        /// <paramref name="configuration"/> are null references (Nothing in VB).</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="connectionString"/> is an
        /// empty string.</exception>
        public AspNetSqlLoggingProvider(LoggingEventType threshold,
                                        AspNetSqlLoggingProviderConfiguration configuration, string connectionString,
                                        LoggingProviderBase fallbackProvider)
            : base(threshold, connectionString, fallbackProvider)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            // We don't have to validate the configuration properties, because the configuration already did
            // this itself.
            this.logQueryString  = configuration.LogQueryString;
            this.logFormData     = configuration.LogFormData;
            this.applicationName = configuration.ApplicationName;
            this.retrievalType   = configuration.RetrievalType;
        }
Example #10
0
 /// <summary>Initializes a new instance of the <see cref="CuttingEdgeLogger"/> class.</summary>
 /// <param name="provider">The provider.</param>
 public CuttingEdgeLogger(LoggingProviderBase provider)
 {
     this.provider = provider;
 }
 public void InitializeLoggingSystem()
 {
     // Calling Logger.Provider starts the initialization of the logging provider system.
     LoggingProviderBase provider = Logger.Provider;
 }
Example #12
0
 protected FakeWindowsEventLogLoggingProvider(LoggingProviderBase fallbackProvider)
     : base(LoggingEventType.Debug, ValidSource, ValidLogName, fallbackProvider)
 {
 }
Example #13
0
 private static FakeXmlFileLoggingProvider CreateValidXmlFileLogger(LoggingProviderBase fallbackProvider)
 {
     return(CreateXmlFileLogger("log.xml", fallbackProvider));
 }
 public FailingSqlLoggingProvider(LoggingProviderBase fallbackProvider)
     : base(fallbackProvider)
 {
 }
Example #15
0
 private static FakeXmlFileLoggingProvider CreateXmlFileLogger(string path,
                                                               LoggingProviderBase fallbackProvider)
 {
     return(new FakeXmlFileLoggingProvider(LoggingEventType.Debug, path, fallbackProvider));
 }
 protected FakeSqlLoggingProvider(LoggingProviderBase fallbackProvider)
     : base(LoggingEventType.Debug, ValidConnectionString, fallbackProvider)
 {
 }
Example #17
0
 public FakeXmlFileLoggingProvider(LoggingEventType severity, string path,
                                   LoggingProviderBase fallbackProvider)
     : base(severity, path, fallbackProvider)
 {
 }
Example #18
0
 public FailingWindowsEventLogLoggingProvider(LoggingProviderBase fallbackProvider)
     : base(fallbackProvider)
 {
 }
Example #19
0
 public FakeAspNetSqlLoggingProvider(LoggingProviderBase fallbackProvider)
     : base(LoggingEventType.Debug, new AspNetSqlLoggingProviderConfiguration("Valid app name"),
            "some unimportant connection string", fallbackProvider)
 {
 }