public void SetUp()
		{
			configurationSource = new DictionaryConfigurationSourceWithHandlersQuery();

			InstrumentationConfigurationSection instrumentationConfig = new InstrumentationConfigurationSection(true, true, true);
			configurationSource.Add(InstrumentationConfigurationSection.SectionName, instrumentationConfig);

			settings = new LoggingSettings();
			configurationSource.Add(LoggingSettings.SectionName, settings);

			settings.SpecialTraceSources.ErrorsTraceSource
				= new TraceSourceData("error", SourceLevels.Off);

			TraceSourceData traceSourceData = new TraceSourceData("blocking", SourceLevels.All);
			traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
			settings.TraceSources.Add(traceSourceData);
			traceSourceData = new TraceSourceData("nonblocking", SourceLevels.All);
			traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));
			settings.TraceSources.Add(traceSourceData);

			TraceListenerData traceListenerData = new CustomTraceListenerData("listener1", typeof(MockBlockingCustomTraceListener), "init 1");
			settings.TraceListeners.Add(traceListenerData);
			traceListenerData = new MockTraceListenerData("listener2");
			settings.TraceListeners.Add(traceListenerData);

			reflectionCache = new ConfigurationReflectionCache();

			MockTraceListener.Reset();
			MockBlockingCustomTraceListener.Reset();
		}
Пример #2
0
        /// <summary>
        /// Initialize a new instance of a <see cref="CategoryTraceSourceNode"/> class with a <see cref="TraceSourceData"/> instance.
        /// </summary>
        /// <param name="traceSourceData">A <see cref="TraceSourceData"/> instance.</param>
        public CategoryTraceSourceNode(TraceSourceData traceSourceData)
        {
            if (null == traceSourceData) throw new ArgumentNullException("traceSourceData");

            Rename(traceSourceData.Name);
            SourceLevels = traceSourceData.DefaultLevel;
        }
Пример #3
0
        private static TypeRegistration CreateLogSourceRegistration(TraceSourceData traceSourceData, string name)
        {
            var registration = traceSourceData.GetRegistrations();

            registration.Name = name;
            return(registration);
        }
        private EntLib.TraceSourceData GetAllEventsSource(SourceLevels level)
        {
            var source = new EntLib.TraceSourceData();
            source.DefaultLevel = level;
            this.AddEventLogTraceListenerReference(source);

            return 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);
		}
Пример #6
0
        private LogSource BuildTraceSource(TraceSourceData tsd, Dictionary <string, TraceListener> listeners)
        {
            var sourceListeners =
                tsd.TraceListeners.Select(
                    tln =>
            {
                TraceListener listener;
                if (!listeners.TryGetValue(tln.Name, out listener))
                {
                    listener            = this.BuildTraceListener(tln.Name, tln);
                    listeners[tln.Name] = listener;
                }

                return(listener);
            });

            return(new LogSource(tsd.Name, sourceListeners, tsd.DefaultLevel, tsd.AutoFlush));
        }
Пример #7
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="LogSource"/> based on an instance of <see cref="TraceSourceData"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <param name="traceListenersCache">The cache of already built trace listeners, used to share trace listeners across <see cref="LogSource"/> instances.</param>
        /// <returns>A fully initialized instance of <see cref="LogSource"/>.</returns>
        public LogSource Create(IBuilderContext context, TraceSourceData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache, TraceListenerCustomFactory.TraceListenerCache traceListenersCache)
        {
            List<TraceListener> traceListeners = new List<TraceListener>(objectConfiguration.TraceListeners.Count);

            foreach (TraceListenerReferenceData traceListenerReference in objectConfiguration.TraceListeners)
            {
                TraceListener traceListener
                    = TraceListenerCustomFactory.Instance.Create(context, traceListenerReference.Name, configurationSource, reflectionCache, traceListenersCache);

                traceListeners.Add(traceListener);
            }

            LogSource createdObject
                = new LogSource(objectConfiguration.Name, traceListeners, objectConfiguration.DefaultLevel);

            InstrumentationAttachmentStrategy instrumentationAttacher = new InstrumentationAttachmentStrategy();
            instrumentationAttacher.AttachInstrumentation(createdObject, configurationSource, reflectionCache);

            return createdObject;
        }
		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 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]);
		}
        public void TraceManagerPolicyCreationDoesNotTryToCreateALogWriter_Bug17444()
        {
            loggingSettings.TraceListeners.Add(new FakeTraceListenerData("fake"));

            TraceSourceData sourceData = new TraceSourceData("name", SourceLevels.All);
            sourceData.TraceListeners.Add(new TraceListenerReferenceData("fake"));
            loggingSettings.TraceSources.Add(sourceData);

            loggingSettings.SpecialTraceSources = new SpecialTraceSourcesData();
            loggingSettings.SpecialTraceSources.AllEventsTraceSource = new TraceSourceData("all", SourceLevels.All);
            loggingSettings.SpecialTraceSources.NotProcessedTraceSource = new TraceSourceData("not processed", SourceLevels.Warning);
            loggingSettings.SpecialTraceSources.ErrorsTraceSource = new TraceSourceData("errors", SourceLevels.Error);

            loggingSettings.DefaultCategory = "name";
            loggingSettings.LogWarningWhenNoCategoriesMatch = true;
            loggingSettings.TracingEnabled = false;


            // the order in which the extensions are added should not matter because they should only record policies
            // but the bug caused an attempt to actually try to build a log writer, and this set up would cause
            // an error because a required extension was not added yet.
            InitializeContainer();
        }
		/// <summary>
		/// Initializes a new instance of <see cref="SpecialTraceSourcesData"/>.
		/// </summary>
		/// <param name="mandatory">The configuration for the optional trace source to send all messages received.</param>
		/// <param name="notProcessed">The configuration for the optional to send messages with unknown categories.</param>
		/// <param name="errors">The configuration for the mandatory trace source to log processing errors.</param>
		public SpecialTraceSourcesData(TraceSourceData mandatory, TraceSourceData notProcessed, TraceSourceData errors)
		{
			this.AllEventsTraceSource = mandatory;
			this.NotProcessedTraceSource = notProcessed;
			this.ErrorsTraceSource = errors;
		}
 private static TypeRegistration CreateLogSourceRegistration(TraceSourceData traceSourceData, string name)
 {
     var registration = traceSourceData.GetRegistrations();
     registration.Name = name;
     return registration;
 }
            ILoggingConfigurationCustomCategoryStart ILoggingConfigurationContd.LogToCategoryNamed(string categoryName)
            {
                if (string.IsNullOrEmpty(categoryName))
                    throw new ArgumentException(CommonResources.ExceptionStringNullOrEmpty, "categoryName");

                currentTraceSource = new TraceSourceData()
                {
                    Name = categoryName
                };

                loggingSettings.TraceSources.Add(currentTraceSource);
                return this;
            }
        public void CanCreateLogWriter()
        {
            CategoryFilterData data = new CategoryFilterData();
            data.Type = typeof(CategoryFilter);
            data.Name = "name";
            data.CategoryFilterMode = CategoryFilterMode.DenyAllExceptAllowed;
            data.CategoryFilters.Add(new CategoryFilterEntry("foo"));
            data.CategoryFilters.Add(new CategoryFilterEntry("bar"));
            loggingSettings.LogFilters.Add(data);

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

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

            loggingSettings.SpecialTraceSources = new SpecialTraceSourcesData();
            loggingSettings.SpecialTraceSources.AllEventsTraceSource = new TraceSourceData("all", SourceLevels.All);
            loggingSettings.SpecialTraceSources.NotProcessedTraceSource = new TraceSourceData("not processed", SourceLevels.Warning);
            loggingSettings.SpecialTraceSources.ErrorsTraceSource = new TraceSourceData("errors", SourceLevels.Error);
            loggingSettings.SpecialTraceSources.ErrorsTraceSource.TraceListeners.Add(new TraceListenerReferenceData("mock1"));

            loggingSettings.DefaultCategory = "name";
            loggingSettings.LogWarningWhenNoCategoriesMatch = true;
            loggingSettings.TracingEnabled = false;

            InitializeContainer();

            LogWriter createdObject = container.Resolve<LogWriter>();

            Assert.IsNotNull(createdObject);

            CategoryFilter filter = createdObject.GetFilter<CategoryFilter>();
            Assert.IsNotNull(filter);
            Assert.AreEqual(2, filter.CategoryFilters.Count);
            Assert.IsTrue(filter.CategoryFilters.Contains("foo"));
            Assert.IsTrue(filter.CategoryFilters.Contains("bar"));

            Assert.AreEqual(1, createdObject.TraceSources.Count);
        }
 private void AddApplicationCategorySource(EntLib.LoggingSettings entLibSettings)
 {
     var source = new EntLib.TraceSourceData(ApplicationEventsCategory, ApplicationLoggingLevel);
     this.AddEventLogTraceListenerReference(source);
     entLibSettings.TraceSources.Add(source);
 }
Пример #16
0
        private LogSource BuildTraceSource(TraceSourceData tsd, Dictionary<string, TraceListener> listeners)
        {
            var sourceListeners =
                tsd.TraceListeners.Select(
                    tln =>
                    {
                        TraceListener listener;
                        if (!listeners.TryGetValue(tln.Name, out listener))
                        {
                            listener = this.BuildTraceListener(tln.Name, tln);
                            listeners[tln.Name] = listener;
                        }

                        return listener;
                    });

            return new LogSource(tsd.Name, sourceListeners, tsd.DefaultLevel, tsd.AutoFlush);
        }
        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);
        }
        private EntLib.TraceSourceData GetErrorsSource(EntLib.LoggingSettings entLibSettings)
        {
            var source = new EntLib.TraceSourceData();
            source.DefaultLevel = SourceLevels.Warning;
            this.AddEventLogTraceListenerReference(source);

            return source;
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of <see cref="SpecialTraceSourcesData"/>.
 /// </summary>
 /// <param name="mandatory">The configuration for the optional trace source to send all messages received.</param>
 /// <param name="notProcessed">The configuration for the optional to send messages with unknown categories.</param>
 /// <param name="errors">The configuration for the mandatory trace source to log processing errors.</param>
 public SpecialTraceSourcesData(TraceSourceData mandatory, TraceSourceData notProcessed, TraceSourceData errors)
 {
     this.AllEventsTraceSource    = mandatory;
     this.NotProcessedTraceSource = notProcessed;
     this.ErrorsTraceSource       = errors;
 }
        public void CanCreateTraceSource()
        {
            loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock1"));
            loggingSettings.TraceListeners.Add(new MockTraceListenerData("mock2"));

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

            InitializeContainer();

            LogSource createdObject = container.Resolve<LogSource>("name");

            Assert.IsNotNull(createdObject);
            Assert.AreEqual("name", createdObject.Name);
            Assert.AreEqual(SourceLevels.All, createdObject.Level);
            Assert.AreEqual(2, createdObject.Listeners.Count);
            Assert.AreSame(typeof(ReconfigurableTraceListenerWrapper), createdObject.Listeners[0].GetType());
            Assert.AreEqual("mock1", createdObject.Listeners[0].Name);
            Assert.AreSame(typeof(ReconfigurableTraceListenerWrapper), createdObject.Listeners[1].GetType());
            Assert.AreEqual("mock2", createdObject.Listeners[1].Name);
        }