Exemple #1
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="LogWriterStructureHolder"/> described by the <see cref="LoggingSettings"/> configuration section.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the instance to build. It is part of the <see cref="ICustomFactory.CreateObject(IBuilderContext, string, IConfigurationSource, ConfigurationReflectionCache)"/> method, but it is not used in this implementation.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="LogWriterStructureHolder"/>.</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            LoggingSettings loggingSettings = LoggingSettings.GetLoggingSettings(configurationSource);

            ValidateLoggingSettings(loggingSettings);

            TraceListenerCustomFactory.TraceListenerCache traceListenerCache
                = TraceListenerCustomFactory.CreateTraceListenerCache(loggingSettings.TraceListeners.Count);

            ICollection <ILogFilter> logFilters = new List <ILogFilter>();

            foreach (LogFilterData logFilterData in loggingSettings.LogFilters)
            {
                logFilters.Add(LogFilterCustomFactory.Instance.Create(context, logFilterData, configurationSource, reflectionCache));
            }

            IDictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>();

            foreach (TraceSourceData traceSourceData in loggingSettings.TraceSources)
            {
                traceSources.Add(traceSourceData.Name, LogSourceCustomFactory.Instance.Create(context, traceSourceData, configurationSource, reflectionCache, traceListenerCache));
            }

            LogSource allEventsTraceSource
                = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.AllEventsTraceSource, configurationSource, reflectionCache, traceListenerCache);
            LogSource notProcessedTraceSource
                = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.NotProcessedTraceSource, configurationSource, reflectionCache, traceListenerCache);
            LogSource errorsTraceSource
                = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.ErrorsTraceSource, configurationSource, reflectionCache, traceListenerCache);

            LogWriterStructureHolder createdObject
                = new LogWriterStructureHolder(
                      logFilters,
                      traceSources,
                      allEventsTraceSource,
                      notProcessedTraceSource,
                      errorsTraceSource,
                      loggingSettings.DefaultCategory,
                      loggingSettings.TracingEnabled,
                      loggingSettings.LogWarningWhenNoCategoriesMatch);

            return(createdObject);
        }
Exemple #2
0
 public void SetUp()
 {
     context            = new BuilderContext(new StrategyChain(), null, null, new PolicyList(), null, null);
     reflectionCache    = new ConfigurationReflectionCache();
     traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(3);
 }
		public void SetUp()
		{
			context = new MockBuilderContext();
			reflectionCache = new ConfigurationReflectionCache();
			traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(3);
		}
 public void SetUp()
 {
     context            = new MockBuilderContext();
     reflectionCache    = new ConfigurationReflectionCache();
     traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(3);
 }
Exemple #5
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 SetUp()
 {
     context = new BuilderContext(new StrategyChain(), null, null, new PolicyList(), null, null);
     reflectionCache = new ConfigurationReflectionCache();
     traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(3);
 }