public void CanCreateInstanceFromGivenName()
        {
            FormattedDatabaseTraceListenerData listenerData =
                new FormattedDatabaseTraceListenerData("listener", "WriteLog", "AddCategory", "LoggingDb", "formatter")
            {
                TraceOutputOptions = TraceOptions.Callstack | TraceOptions.DateTime,
                Filter             = SourceLevels.Information
            };
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "some template"));
            helper.loggingSettings.TraceListeners.Add(listenerData);

            var listener = (FormattedDatabaseTraceListener)GetListener("listener", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(TraceOptions.Callstack | TraceOptions.DateTime, listener.TraceOutputOptions);
            Assert.IsNotNull(listener.Filter);
            Assert.AreEqual(SourceLevels.Information, ((EventTypeFilter)listener.Filter).EventType);
            Assert.AreEqual("WriteLog", listener.WriteLogStoredProcName);
            Assert.AreEqual("AddCategory", listener.AddCategoryStoredProcName);
            Assert.AreEqual(@"server=(localdb)\v11.0;database=Logging;Integrated Security=true", listener.Database.ConnectionString);
            Assert.IsNotNull(listener.Formatter);
            Assert.AreEqual(listener.Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("some template", ((TextFormatter)listener.Formatter).Template);
        }
        public void CanCreateInstanceFromGivenName()
        {
            FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", "unknown source", "formatter");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "some template"));
            helper.loggingSettings.TraceListeners.Add(listenerData);

            TraceListener listener = GetListener("listener", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(FormattedEventLogTraceListener));
            FormattedEventLogTraceListener castedListener = (FormattedEventLogTraceListener)listener;

            Assert.IsNotNull(castedListener.Formatter);
            Assert.AreEqual("unknown source", ((EventLogTraceListener)castedListener.InnerListener).EventLog.Source);
            Assert.AreEqual(FormattedEventLogTraceListener.DefaultMachineName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.MachineName);
            Assert.AreEqual(castedListener.Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("some template", ((TextFormatter)castedListener.Formatter).Template);

            try
            {
                Assert.AreEqual(FormattedEventLogTraceListener.DefaultLogName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.Log);
            }
            catch (SecurityException ex)
            {
                Assert.Inconclusive("In order to run the tests, please run Visual Studio as Administrator.\r\n{0}", ex.ToString());
            }
        }
        public void ManyTraceSourcesWithReferenceToSameTraceListenerGetSameInstanceIfSharingCache()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock1"));
            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock2"));

            TraceSourceData sourceData1 = new TraceSourceData("notfromconfiguration1", SourceLevels.All);
            sourceData1.TraceListeners.Add(new TraceListenerReferenceData("mock1"));
            sourceData1.TraceListeners.Add(new TraceListenerReferenceData("mock2"));

            TraceSourceData sourceData2 = new TraceSourceData("notfromconfiguration2", SourceLevels.All);
            sourceData2.TraceListeners.Add(new TraceListenerReferenceData("mock1"));

            LogSource traceSource1
                = LogSourceCustomFactory.Instance.Create(context, sourceData1, helper.configurationSource, reflectionCache, traceListenerCache);
            LogSource traceSource2
                = LogSourceCustomFactory.Instance.Create(context, sourceData2, helper.configurationSource, reflectionCache, traceListenerCache);

            Assert.IsNotNull(traceSource1);
            Assert.IsNotNull(traceSource2);
            Assert.IsFalse(traceSource1 == traceSource2);
            Assert.AreEqual("mock1", traceSource1.Listeners[0].Name);
            Assert.AreEqual("mock1", traceSource2.Listeners[0].Name);
            Assert.AreSame(traceSource1.Listeners[0], traceSource2.Listeners[0]);
        }
Beispiel #4
0
        public void CreationOfCustomTraceListenerWithoutRequiredSignatureConstructorThrows()
        {
            CustomTraceListenerData listenerData
                = new CustomTraceListenerData("listener", typeof(MockCustomTraceListenerWithInvalidConstructor), initializationData);

            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);
        }
        public void CreatedTraceListenerWithDefaultFilter()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("listener"));
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNull(listener.Filter);
        }
        public void CreationOfCustomTraceListenerWithoutRequiredSignatureConstructorThrows()
        {
            CustomTraceListenerData listenerData
                = new CustomTraceListenerData("listener", typeof(MockCustomTraceListenerWithInvalidConstructor), initializationData);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener = GetListener("listener", helper.configurationSource);
        }
Beispiel #7
0
        public void PriorityFilterMaximumPriotDefaultsToMaxIntWhenNotSpecified()
        {
            PriorityFilterData   filterData = new PriorityFilterData(1000);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();
            ILogFilter           filter     = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(PriorityFilter));
            Assert.AreEqual(int.MaxValue, ((PriorityFilter)filter).MaximumPriority);
        }
Beispiel #8
0
        public void CanCreatePriorityFilterFromConfiguration()
        {
            PriorityFilterData   filterData = new PriorityFilterData(1000);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();
            ILogFilter           filter     = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(PriorityFilter));
            Assert.AreEqual(1000, ((PriorityFilter)filter).MinimumPriority);
        }
        public void CreationWithExistingTraceListenerDataSucceeeds()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("listener"));

            TraceListener listener
                = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreSame(typeof(MockTraceListener), listener.GetType());
        }
Beispiel #10
0
        public void CanCreateInstanceFromGivenConfiguration()
        {
            WmiTraceListenerData listenerData =
                new WmiTraceListenerData("listener");
            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(WmiTraceListener));
        }
Beispiel #11
0
        public void CanCreateLogEnabledFilterFromConfiguration()
        {
            LogEnabledFilterData filterData = new LogEnabledFilterData(true);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();
            ILogFilter           filter     = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(LogEnabledFilter));
            Assert.AreEqual(true, ((LogEnabledFilter)filter).Enabled);
        }
        public void CreatedTraceListenerWithAllFilterOption()
        {
            MockLogObjectsHelper  helper = new MockLogObjectsHelper();
            MockTraceListenerData data   = new MockTraceListenerData("listener");

            data.Filter = SourceLevels.All;
            helper.loggingSettings.TraceListeners.Add(data);
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNull(listener.Filter);
        }
Beispiel #13
0
        public void CanCreateInstanceFromGivenConfiguration()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(DelimitedListTraceListener), "log.txt");
            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(typeof(DelimitedListTraceListener), listener.GetType());
        }
        public void CreationWithExistingTraceListenerDataSucceeeds()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("listener"));
            TraceListener listener
                = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreSame(typeof(MockTraceListener), listener.GetType());
        }
		public void CanCreateInstanceFromGivenConfiguration()
		{
			SystemDiagnosticsTraceListenerData listenerData
				= new SystemDiagnosticsTraceListenerData("listener", typeof(DelimitedListTraceListener), "log.txt");

			MockLogObjectsHelper helper = new MockLogObjectsHelper();
			TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);

			Assert.IsNotNull(listener);
			Assert.AreEqual("listener", listener.Name);
			Assert.AreEqual(typeof(DelimitedListTraceListener), listener.GetType());
		}
        public void CanCreateInstanceFromGivenConfiguration()
        {
            WmiTraceListenerData listenerData =
                    new WmiTraceListenerData("listener");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(WmiTraceListener));
        }
Beispiel #17
0
        public void CanCreateInstanceFromGivenConfiguration()
        {
            RollingFlatFileTraceListenerData listenerData = new RollingFlatFileTraceListenerData("listener", "log.txt", "header", "footer", 10, "yyyy-MM-dd", RollFileExistsBehavior.Increment,
                                                                                                 RollInterval.Minute, TraceOptions.DateTime, "SimpleTextFormat");
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.Formatters.Add(new TextFormatterData("SimpleTextFormat", "foobar template"));
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(RollingFlatFileTraceListener));
        }
        public void PriorityFilterMaximumPriotDefaultsToMaxIntWhenNotSpecified()
        {
            PriorityFilterData   filterData = new PriorityFilterData(1000);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();

            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(PriorityFilter));
            Assert.AreEqual(int.MaxValue, ((PriorityFilter)filter).MaximumPriority);
        }
Beispiel #19
0
        public void CanCreateInstanceFromGivenConfigurationWithoutFormatter()
        {
            EmailTraceListenerData listenerData =
                new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:",
                                           "has occurred", "smtphost", 25, null);
            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(EmailTraceListener));
            Assert.IsNull(((EmailTraceListener)listener).Formatter);
        }
Beispiel #20
0
        public void CanCreateCategoryFilterFromEmptyCategoryConfiguration()
        {
            NamedElementCollection <CategoryFilterEntry> categoryEntries = new NamedElementCollection <CategoryFilterEntry>();
            CategoryFilterData   filterData = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.DenyAllExceptAllowed);
            MockLogObjectsHelper helper     = new MockLogObjectsHelper();
            ILogFilter           filter     = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(0, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.AreEqual(CategoryFilterMode.DenyAllExceptAllowed, ((CategoryFilter)filter).CategoryFilterMode);
        }
        public void CanCreateLogEnabledFilterFromConfiguration()
        {
            LogEnabledFilterData filterData = new LogEnabledFilterData(true);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(LogEnabledFilter));
            Assert.AreEqual(true, ((LogEnabledFilter)filter).Enabled);
        }
        public void CanCreatePriorityFilterFromConfiguration()
        {
            PriorityFilterData filterData = new PriorityFilterData(1000);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(PriorityFilter));
            Assert.AreEqual(1000, ((PriorityFilter)filter).MinimumPriority);
        }
Beispiel #23
0
        public void CanBuildCustomLogFilterFromGivenConfiguration()
        {
            CustomLogFilterData filterData
                = new CustomLogFilterData("custom", typeof(MockCustomLogFilter));

            filterData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            ILogFilter           filter = LogFilterCustomFactory.Instance.Create(new MockBuilderContext(), filterData, helper.configurationSource, new ConfigurationReflectionCache());

            Assert.IsNotNull(filter);
            Assert.AreSame(typeof(MockCustomLogFilter), filter.GetType());
            Assert.AreEqual("value1", ((MockCustomLogFilter)filter).customValue);
        }
		public void CanCreateInstanceFromGivenName()
		{
			CustomTraceListenerData listenerData
				= new CustomTraceListenerData("listener", typeof(MockCustomTraceListener), initializationData);

			MockLogObjectsHelper helper = new MockLogObjectsHelper();
			helper.loggingSettings.TraceListeners.Add(listenerData);
			TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

			Assert.IsNotNull(listener);
			Assert.AreEqual("listener", listener.Name);
			Assert.AreEqual(typeof(MockCustomTraceListener), listener.GetType());
			Assert.AreEqual(initializationData, ((MockCustomTraceListener)listener).initData);
		}
        public void CanCreateInstanceFromGivenConfiguration()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(TextWriterTraceListener), "log.txt");

            listenerData.TraceOutputOptions = TraceOptions.Callstack;
            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual(listener.GetType(), typeof(TextWriterTraceListener));
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(TraceOptions.Callstack, listener.TraceOutputOptions);
        }
        public void CreatedTraceListenerHasCorrectFilter()
        {
            MockLogObjectsHelper  helper = new MockLogObjectsHelper();
            MockTraceListenerData data   = new MockTraceListenerData("listener");

            data.Filter = SourceLevels.Critical;
            helper.loggingSettings.TraceListeners.Add(data);
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener.Filter);
            EventTypeFilter filter = (EventTypeFilter)listener.Filter;

            Assert.AreEqual(data.Filter, filter.EventType);
        }
Beispiel #27
0
        public void PriorityFilterShouldNotLogWhenPriotityIsAboveMaxPriority()
        {
            PriorityFilterData filterData = new PriorityFilterData(0);

            filterData.MaximumPriority = 100;
            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            ILogFilter           filter = LogFilterCustomFactory.Instance.Create(context, filterData, helper.configurationSource, reflectionCache);

            ;
            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(PriorityFilter));
            Assert.IsTrue(((PriorityFilter)filter).ShouldLog(100));
            Assert.IsFalse(((PriorityFilter)filter).ShouldLog(101));
        }
        public void CanCreateInstanceFromGivenName()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(EventLogTraceListener), "Entlib Tests");
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(EventLogTraceListener));
            Assert.AreEqual("Entlib Tests", ((EventLogTraceListener)listener).EventLog.Source);
        }
        public void CreatedTraceSourceWithNoListenersFromConfigurationIsEmpty()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            TraceSourceData sourceData = new TraceSourceData("notfromconfiguration", SourceLevels.All);

            LogSource traceSource
                = LogSourceCustomFactory.Instance.Create(context, sourceData, helper.configurationSource, reflectionCache, traceListenerCache);

            Assert.IsNotNull(traceSource);
            Assert.AreEqual("notfromconfiguration", traceSource.Name);
            Assert.AreEqual(SourceLevels.All, traceSource.Level);
            Assert.AreEqual(0, traceSource.Listeners.Count);
        }
        public void CanCreateInstanceFromGivenName()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(DelimitedListTraceListener), "log.txt");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);

            TraceListener listener = GetListener("listener", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(typeof(DelimitedListTraceListener), listener.GetType());
        }
        public void CanCreateInstanceFromGivenConfiguration()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(TextWriterTraceListener), "log.txt");
            listenerData.TraceOutputOptions = TraceOptions.Callstack;

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual(listener.GetType(), typeof(TextWriterTraceListener));
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(TraceOptions.Callstack, listener.TraceOutputOptions);
        }
        public void CanCreateInstanceFromGivenName()
        {
            WmiTraceListenerData listenerData =
                new WmiTraceListenerData("listener");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener =
                GetListener("listener\u200cimplementation", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener\u200cimplementation", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(WmiTraceListener));
        }
        public void CanCreateInstanceFromGivenConfiguration()
        {
            FlatFileTraceListenerData listenerData = new FlatFileTraceListenerData("listener", "log.txt", "---header---", "+++footer+++", "formatter");
            MockLogObjectsHelper      helper       = new MockLogObjectsHelper();

            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "foobar template"));
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(FlatFileTraceListener));
            Assert.IsNotNull(((FlatFileTraceListener)listener).Formatter);
            Assert.AreEqual(((FlatFileTraceListener)listener).Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("foobar template", ((TextFormatter)((FlatFileTraceListener)listener).Formatter).Template);
        }
Beispiel #34
0
        public void CanCreateInstanceFromGivenName()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(EventLogTraceListener), "Entlib Tests");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener = GetListener("listener\u200cimplementation", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener\u200cimplementation", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(EventLogTraceListener));
            Assert.AreEqual("Entlib Tests", ((EventLogTraceListener)listener).EventLog.Source);
        }
        public void CanCreateInstanceFromGivenName()
        {
            CustomTraceListenerData listenerData
                = new CustomTraceListenerData("listener", typeof(MockCustomTraceListener), initializationData);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener = GetListener("listener", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(typeof(MockCustomTraceListener), listener.GetType());
            Assert.AreEqual(initializationData, ((MockCustomTraceListener)listener).initData);
        }
        public void CanCreateCategoryFilterFromEmptyCategoryConfiguration()
        {
            var categoryEntries = new NamedElementCollection <CategoryFilterEntry>();
            var filterData      = new CategoryFilterData("category", categoryEntries, CategoryFilterMode.DenyAllExceptAllowed);

            var helper = new MockLogObjectsHelper();

            helper.loggingSettings.LogFilters.Add(filterData);

            ILogFilter filter = GetFilter(filterData.Name, helper.configurationSource);

            Assert.IsNotNull(filter);
            Assert.AreEqual(filter.GetType(), typeof(CategoryFilter));
            Assert.AreEqual(0, ((CategoryFilter)filter).CategoryFilters.Count);
            Assert.AreEqual(CategoryFilterMode.DenyAllExceptAllowed, ((CategoryFilter)filter).CategoryFilterMode);
        }
Beispiel #37
0
        public void CanCreateInstanceFromGivenConfigurationWithAttributes()
        {
            CustomTraceListenerData listenerData
                = new CustomTraceListenerData("listener", typeof(MockCustomTraceListener), initializationData);

            listenerData.SetAttributeValue(MockCustomTraceListener.AttributeKey, attributeValue);

            MockLogObjectsHelper helper   = new MockLogObjectsHelper();
            TraceListener        listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(typeof(MockCustomTraceListener), listener.GetType());
            Assert.AreEqual(initializationData, ((MockCustomTraceListener)listener).initData);
            Assert.AreEqual(attributeValue, ((MockCustomTraceListener)listener).Attribute);
        }
        public void CanCreateInstanceFromGiveName()
        {
            FlatFileTraceListenerData listenerData = new FlatFileTraceListenerData("listener", "log.txt", "---header---", "+++footer+++", "formatter");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.TraceListeners.Add(listenerData);
            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "foobar template"));

            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(FlatFileTraceListener));
            Assert.IsNotNull(((FlatFileTraceListener)listener).Formatter);
            Assert.AreEqual(((FlatFileTraceListener)listener).Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("foobar template", ((TextFormatter)((FlatFileTraceListener)listener).Formatter).Template);
        }
        public void CanCreateInstanceFromGivenConfiguration()
        {
            EmailTraceListenerData listenerData =
                    new EmailTraceListenerData("listener", "[email protected]", "*****@*****.**", "EntLib-Logging:",
                                                    "has occurred", "smtphost", 25, "formatter");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "foobar template"));

            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(EmailTraceListener));
            Assert.IsNotNull(((EmailTraceListener)listener).Formatter);
            Assert.AreEqual(((EmailTraceListener)listener).Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("foobar template", ((TextFormatter)((EmailTraceListener)listener).Formatter).Template);
        }
        public void CreatedTraceSourceWithListenersFromConfigurationHasCorrectCountOfListeners()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock1"));
            helper.loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock2"));

            TraceSourceData sourceData = new TraceSourceData("notfromconfiguration", SourceLevels.All);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("mock1"));
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("mock2"));

            LogSource traceSource
                = LogSourceCustomFactory.Instance.Create(context, sourceData, helper.configurationSource, reflectionCache, traceListenerCache);

            Assert.IsNotNull(traceSource);
            Assert.AreEqual("notfromconfiguration", traceSource.Name);
            Assert.AreEqual(SourceLevels.All, traceSource.Level);
            Assert.AreEqual(2, traceSource.Listeners.Count);
            Assert.AreSame(typeof(MockTraceListener), traceSource.Listeners[0].GetType());
            Assert.AreEqual("mock1", traceSource.Listeners[0].Name);
            Assert.AreSame(typeof(MockTraceListener), traceSource.Listeners[1].GetType());
            Assert.AreEqual("mock2", traceSource.Listeners[1].Name);
        }
        public void CanCreateInstanceFromGivenName()
        {
            FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", "unknown source", "formatter");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.Formatters.Add(new TextFormatterData("formatter", "foobar template"));
            helper.loggingSettings.TraceListeners.Add(listenerData);

            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(FormattedEventLogTraceListener));
            FormattedEventLogTraceListener castedListener = (FormattedEventLogTraceListener)listener;
            Assert.IsNotNull(castedListener.Formatter);
            Assert.AreEqual("unknown source", ((EventLogTraceListener)castedListener.SlaveListener).EventLog.Source);
            Assert.AreEqual(FormattedEventLogTraceListener.DefaultLogName, ((EventLogTraceListener)castedListener.SlaveListener).EventLog.Log);
            Assert.AreEqual(FormattedEventLogTraceListener.DefaultMachineName, ((EventLogTraceListener)castedListener.SlaveListener).EventLog.MachineName);
            Assert.AreEqual(castedListener.Formatter.GetType(), typeof(TextFormatter));
            Assert.AreEqual("foobar template", ((TextFormatter)castedListener.Formatter).Template);
        }
        public void CanCreateInstanceFromGivenName()
        {
            SystemDiagnosticsTraceListenerData listenerData
                = new SystemDiagnosticsTraceListenerData("listener", typeof(EventLogTraceListener), "Entlib Tests");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.TraceListeners.Add(listenerData);
            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(EventLogTraceListener));
            Assert.AreEqual("Entlib Tests", ((EventLogTraceListener)listener).EventLog.Source);
        }
        public void CreationWithMissingTraceListenerDataThrows()
        {
            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            TraceListenerCustomFactory.Instance.Create(context, "listener", helper.configurationSource, reflectionCache);
        }
        public void CreateTraceSourceWithAutoFlushSetToFalse()
        {
            bool autoFlush = false;
            TraceSourceData sourceData = new TraceSourceData("notfromconfiguration", SourceLevels.All, autoFlush);

            MockLogObjectsHelper helper = new MockLogObjectsHelper();

            LogSource logSource = LogSourceCustomFactory.Instance.Create(context, sourceData, helper.configurationSource, reflectionCache, traceListenerCache);

            Assert.IsNotNull(logSource);
            Assert.AreEqual(autoFlush, logSource.AutoFlush);
        }
		public void CreationOfCustomTraceListenerWithoutRequiredSignatureConstructorThrows()
		{
			CustomTraceListenerData listenerData
				= new CustomTraceListenerData("listener", typeof(MockCustomTraceListenerWithInvalidConstructor), initializationData);

			MockLogObjectsHelper helper = new MockLogObjectsHelper();
			TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);
		}
		public void CanCreateInstanceFromGivenConfigurationWithAttributes()
		{
			CustomTraceListenerData listenerData
				= new CustomTraceListenerData("listener", typeof(MockCustomTraceListener), initializationData);
			listenerData.SetAttributeValue(MockCustomTraceListener.AttributeKey, attributeValue);

			MockLogObjectsHelper helper = new MockLogObjectsHelper();
			TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);

			Assert.IsNotNull(listener);
			Assert.AreEqual("listener", listener.Name);
			Assert.AreEqual(typeof(MockCustomTraceListener), listener.GetType());
			Assert.AreEqual(initializationData, ((MockCustomTraceListener)listener).initData);
			Assert.AreEqual(attributeValue, ((MockCustomTraceListener)listener).Attribute);
		}
		public void CanCreateInstanceFromGivenConfiguration()
		{
			TraceListenerData listenerData = new MsmqTraceListenerData("listener", CommonUtil.MessageQueuePath, formatterName);

			MockLogObjectsHelper helper = new MockLogObjectsHelper();
			helper.loggingSettings.Formatters.Add(new BinaryLogFormatterData(formatterName));

			TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, listenerData, helper.configurationSource,reflectionCache);

			Assert.IsNotNull(listener);
			Assert.AreEqual(listener.GetType(), typeof(MsmqTraceListener));

			MsmqTraceListener msmqTraceListener = listener as MsmqTraceListener;
			Assert.AreEqual("listener", listener.Name);
			Assert.IsNotNull(msmqTraceListener.Formatter);
			Assert.AreEqual(msmqTraceListener.Formatter.GetType(), typeof(BinaryLogFormatter));
			Assert.AreEqual(CommonUtil.MessageQueuePath, msmqTraceListener.QueuePath);
		}