public override object BuildUp(IBuilderContext context, Type t, object existing, string id) { if (existing != null) { IConfigurationSource configurationSource = base.GetConfigurationSource(context); ConfigurationReflectionCache reflectionCache = base.GetReflectionCache(context); InstrumentationAttachmentStrategy strategy = new InstrumentationAttachmentStrategy(); if (ConfigurationNameProvider.IsMadeUpName(id)) { strategy.AttachInstrumentation(existing, configurationSource, reflectionCache); } else { strategy.AttachInstrumentation(id, existing, configurationSource, reflectionCache); } } return base.BuildUp(context, t, existing, id); }
public override void PreBuildUp(IBuilderContext context) { base.PreBuildUp(context); if (context.Existing != null && context.Existing is IInstrumentationEventProvider) { IConfigurationSource configurationSource = GetConfigurationSource(context); ConfigurationReflectionCache reflectionCache = GetReflectionCache(context); NamedTypeBuildKey key = (NamedTypeBuildKey)context.BuildKey; string id = key.Name; InstrumentationAttachmentStrategy instrumentation = new InstrumentationAttachmentStrategy(); if (ConfigurationNameProvider.IsMadeUpName(id)) { instrumentation.AttachInstrumentation(context.Existing, configurationSource, reflectionCache); } else { instrumentation.AttachInstrumentation(id, context.Existing, configurationSource, reflectionCache); } } }
/// <summary> /// Implementation of <see cref="IBuilderStrategy.BuildUp"/>. /// </summary> /// <remarks> /// This implementation will attach instrumentation to the created objects. /// </remarks> /// <param name="context">The build context.</param> /// <param name="t">The type of the object being built.</param> /// <param name="existing">The existing instance of the object.</param> /// <param name="id">The ID of the object being built.</param> /// <returns>The built object.</returns> public override object BuildUp(IBuilderContext context, Type t, object existing, string id) { if (existing != null) { IConfigurationSource configurationSource = GetConfigurationSource(context); ConfigurationReflectionCache reflectionCache = GetReflectionCache(context); InstrumentationAttachmentStrategy instrumentation = new InstrumentationAttachmentStrategy(); if (ConfigurationNameProvider.IsMadeUpName(id)) { instrumentation.AttachInstrumentation(existing, configurationSource, reflectionCache); } else { instrumentation.AttachInstrumentation(id, existing, configurationSource, reflectionCache); } } return(base.BuildUp(context, t, existing, id)); }
public void InstrumentationIsNotAttachedIfConfigurationIsMissing() { DictionaryConfigurationSource dictionary = new DictionaryConfigurationSource(); InstrumentationAttachmentStrategy attacher = new InstrumentationAttachmentStrategy(); ConfigurationReflectionCache reflectionCache = new ConfigurationReflectionCache(); SourceObject sourceObject = new SourceObject(); attacher.AttachInstrumentation(sourceObject, dictionary, reflectionCache); Assert.IsFalse(ShouldNeverBeInstantiatedListener.WasInstantiated); }
public void InstrumentationIsNotAttachedIfAllConfigOptionsAreFalse() { DictionaryConfigurationSource dictionary = new DictionaryConfigurationSource(); dictionary.Add(InstrumentationConfigurationSection.SectionName, new InstrumentationConfigurationSection(false, false, false)); InstrumentationAttachmentStrategy attacher = new InstrumentationAttachmentStrategy(); ConfigurationReflectionCache reflectionCache = new ConfigurationReflectionCache(); SourceObject sourceObject = new SourceObject(); attacher.AttachInstrumentation(sourceObject, dictionary, reflectionCache); Assert.IsFalse(ShouldNeverBeInstantiatedListener.WasInstantiated); }
/// <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; }