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]); }
/// <summary> /// This will instantiate trace sources and then trace this to the specified source. Pass null if you don't want to trace. /// Note that trace sources of the same name share the same Listeners, so they are effectively distinguished by name rather than instance /// hence keeping them in a dictionary andnot a list /// </summary> /// <param name="traceTo"></param> /// <param name="eventId"></param> static public void InitFromAppConfig(String traceTo, int eventId = 0) { AppConfig.ReadConfig(); var traceOutput = new List <String>(); if (_traceSources == null) { _traceSources = new Dictionary <String, TraceSourceData>(); foreach (var sn in AppConfig.SourceNames) { _traceSources[sn] = new TraceSourceData(sn); traceOutput.Add(String.Format("Creating TraceSource instance for source {0}", sn)); } } if (traceTo != null && _traceSources.ContainsKey(traceTo)) { var ts = _traceSources[traceTo].TS; foreach (var o in traceOutput) { ts.TraceEvent(TraceEventType.Information, eventId, o); } } }
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. container.AddNewExtension <LoggingBlockExtension>(); container.AddNewExtension <FakeBlockExtension>(); }
private static void BuildTraceListenerReferences(TraceSourceData data, TraceSourceNode node) { foreach (TraceListenerReferenceNode refNode in node.Nodes) { data.TraceListeners.Add(refNode.TraceListenerReferenceData); } }
public void CanDeserializeSerializedConfiguration() { string name = "name"; TraceSourceData data = new TraceSourceData(name, SourceLevels.Critical); data.TraceListeners.Add(new TraceListenerReferenceData("listener1")); data.TraceListeners.Add(new TraceListenerReferenceData("listener2")); LoggingSettings settings = new LoggingSettings(); settings.TraceSources.Add(data); IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(1, roSettigs.TraceSources.Count); Assert.IsNotNull(roSettigs.TraceSources.Get(name)); Assert.AreEqual(SourceLevels.Critical, roSettigs.TraceSources.Get(name).DefaultLevel); Assert.AreEqual(2, roSettigs.TraceSources.Get(name).TraceListeners.Count); Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener1")); Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener2")); }
/// <summary> /// Initialize a new instance of the <see cref="NotProcessedTraceSourceNode"/> with a <see cref="TraceSourceData"/> instance. /// </summary> /// <param name="traceSourceData">A <see cref="TraceSourceData"/> instance.</param> public NotProcessedTraceSourceNode(TraceSourceData traceSourceData) : base(Resources.UnprocessedTraceSourceNode) { if (null == traceSourceData) throw new ArgumentNullException("traceSourceData"); SourceLevels = traceSourceData.DefaultLevel; }
public void SetUp() { configurationSource = new DictionaryConfigurationSourceWithHandlersQuery(); InstrumentationConfigurationSection instrumentationConfig = new InstrumentationConfigurationSection(true, true, false); 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(); }
private static void AddTraceSourcePolicy( TraceSourceData traceSourceData, String traceSourceName, String parentKey, AdmContentBuilder contentBuilder, LoggingSettings configurationSection) { String traceSourceKey = parentKey + @"\" + traceSourceName; contentBuilder.StartPolicy(String.Format(CultureInfo.InvariantCulture, Resources.TraceSourcePolicyNameTemplate, traceSourceName), traceSourceKey); { contentBuilder.AddDropDownListPartForEnumeration <SourceLevels>(Resources.TraceSourceDefaultLevelPartName, SourceDefaultLevelPropertyName, traceSourceData.DefaultLevel); contentBuilder.AddTextPart(Resources.TraceSourceListenersPartName); String traceSourceListenersKey = traceSourceKey + @"\" + SourceTraceListenersPropertyName; foreach (TraceListenerData traceListener in configurationSection.TraceListeners) { contentBuilder.AddCheckboxPart(traceListener.Name, traceSourceListenersKey, traceListener.Name, traceSourceData.TraceListeners.Contains(traceListener.Name), true, false); } } contentBuilder.EndPolicy(); }
protected LogWriter GetWriter(string fileName) { DictionaryConfigurationSource config = new DictionaryConfigurationSource(); var logging = new LoggingSettings(); logging.TracingEnabled = true; logging.Name = "Logging Application Block"; logging.DefaultCategory = "General"; logging.Formatters.Add(new BinaryLogFormatterData("Binary Formatter")); logging.TraceListeners.Add( new FlatFileTraceListenerData() { Name = "TraceListener", FileName = fileName, TraceOutputOptions = TraceOptions.None, Filter = SourceLevels.All, Formatter = "Binary Formatter", Type = typeof(FlatFileTraceListener) }); var traceSource = new TraceSourceData("General", SourceLevels.Information, true); traceSource.TraceListeners.Add(new TraceListenerReferenceData("TraceListener")); logging.TraceSources.Add(traceSource); config.Add(LoggingSettings.SectionName, logging); this.ConfigurationSource = config; LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(LoggingSettings.SectionName)); return(factory.Create()); }
private static void BuildTraceListenerReferences(TraceSourceData data, TraceSourceNode node) { foreach (TraceListenerReferenceNode refNode in node.Nodes) { data.TraceListeners.Add(refNode.TraceListenerReferenceData); } }
public void CanDeserializeSerializedWithAutoFlushConfiguration() { string name = "name"; bool autoFlush = false; TraceSourceData data = new TraceSourceData(name, SourceLevels.Critical, false); data.TraceListeners.Add(new TraceListenerReferenceData("listener1")); data.TraceListeners.Add(new TraceListenerReferenceData("listener2")); LoggingSettings settings = new LoggingSettings(); settings.TraceSources.Add(data); IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(1, roSettigs.TraceSources.Count); Assert.IsNotNull(roSettigs.TraceSources.Get(name)); Assert.AreEqual(SourceLevels.Critical, roSettigs.TraceSources.Get(name).DefaultLevel); Assert.AreEqual(autoFlush, roSettigs.TraceSources.Get(name).AutoFlush); Assert.AreEqual(2, roSettigs.TraceSources.Get(name).TraceListeners.Count); Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener1")); Assert.IsNotNull(roSettigs.TraceSources.Get(name).TraceListeners.Get("listener2")); }
private void ConfigureContainer(string fileName) { DictionaryConfigurationSource config = new DictionaryConfigurationSource(); var logging = new LoggingSettings(); logging.TracingEnabled = true; logging.Name = "Logging Application Block"; logging.DefaultCategory = "General"; logging.Formatters.Add(new BinaryLogFormatterData("Binary Formatter")); logging.TraceListeners.Add( new FlatFileTraceListenerData() { Name = "TraceListener", FileName = fileName, TraceOutputOptions = TraceOptions.None, Filter = SourceLevels.All, Formatter = "Binary Formatter", Type = typeof(FlatFileTraceListener) }); var traceSource = new TraceSourceData("General", SourceLevels.Information, true); traceSource.TraceListeners.Add(new TraceListenerReferenceData("TraceListener")); logging.TraceSources.Add(traceSource); config.Add("loggingConfiguration101", logging); this.ConfigurationSource = config; }
private void OverrideWithGroupPoliciesForSpecialTraceSource( String sourceName, TraceSourceData traceSourceData, bool readGroupPolicies, IRegistryKey machineParentKey, IRegistryKey userParentKey, String sourceKind) { if (readGroupPolicies) { IRegistryKey machineSourceKey = null; IRegistryKey userSourceKey = null; try { LoadRegistrySubKeys(sourceName, machineParentKey, userParentKey, out machineSourceKey, out userSourceKey); if (!OverrideWithGroupPoliciesForTraceSource(traceSourceData, readGroupPolicies, machineSourceKey, userSourceKey, sourceKind)) { // "special" trace sources cannot be removed because they aren't elements in collections // but a trace source is considered disabled if it has no trace listeners traceSourceData.TraceListeners.Clear(); } } finally { ReleaseRegistryKeys(machineSourceKey, userSourceKey); } } }
/// <summary> /// Initialize a new instance of the <see cref="ErrorsTraceSourceNode"/> with a <see cref="TraceSourceData"/> instance. /// </summary> /// <param name="traceSourceData">A <see cref="TraceSourceData"/> instance.</param> public ErrorsTraceSourceNode(TraceSourceData traceSourceData) : base(Resources.ErrorsTraceSourceNode) { if (null == traceSourceData) throw new ArgumentNullException("traceSourceData"); SourceLevels = traceSourceData.DefaultLevel; }
public NotProcessedTraceSourceNode(TraceSourceData traceSourceData) : base(Resources.UnprocessedTraceSourceNode) { if (null == traceSourceData) { throw new ArgumentNullException("traceSourceData"); } SourceLevels = traceSourceData.DefaultLevel; }
private bool OverrideWithGroupPoliciesAndGenerateWmiObjectsForTraceSource(TraceSourceData traceSourceData, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings, String sourceKind) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { SourceLevels?defaultLevelOverride = policyKey.GetEnumValue <SourceLevels>(SourceDefaultLevelPropertyName); // the key where the values for the source listeners are stored // might not exist if no listener is selected traceSourceData.TraceListeners.Clear(); using (IRegistryKey listenersOverrideKey = policyKey.OpenSubKey(SourceTraceListenersPropertyName)) { if (listenersOverrideKey != null) { foreach (String valueName in listenersOverrideKey.GetValueNames()) { traceSourceData.TraceListeners.Add(new TraceListenerReferenceData(valueName)); } } } traceSourceData.DefaultLevel = defaultLevelOverride.Value; } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } if (generateWmiObjects) { String[] referencedTraceListeners = new String[traceSourceData.TraceListeners.Count]; for (int i = 0; i < traceSourceData.TraceListeners.Count; i++) { referencedTraceListeners[i] = traceSourceData.TraceListeners.Get(i).Name; } wmiSettings.Add( new TraceSourceSetting( traceSourceData.Name, traceSourceData.DefaultLevel.ToString(), referencedTraceListeners, sourceKind)); } return(true); }
public CategoryTraceSourceNode(TraceSourceData traceSourceData) { if (null == traceSourceData) { throw new ArgumentNullException("traceSourceData"); } Rename(traceSourceData.Name); SourceLevels = traceSourceData.DefaultLevel; }
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 TraceSourceSetting(TraceSourceData sourceElement, string name, string defaultLevel, string[] traceListeners, string kind) : base(sourceElement, name) { this.defaultLevel = defaultLevel; this.traceListeners = traceListeners; this.kind = kind; }
public void Setup() { data = new TraceSourceData("source", SourceLevels.Error, true) { TraceListeners = { new TraceListenerReferenceData("listener1"), new TraceListenerReferenceData("listener2") } }; }
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 TraceSourceDataFromTraceSourceNode() { string name = "name"; bool defaultAutoFlush = false; SourceLevels defaultSourceLevel = SourceLevels.All; TraceSourceNode node = new TraceSourceNodeImpl(name, defaultSourceLevel, defaultAutoFlush); TraceSourceData data = new TraceSourceData(name, defaultSourceLevel, defaultAutoFlush); Assert.AreEqual(node.Name, data.Name); Assert.AreEqual(node.SourceLevels, data.DefaultLevel); Assert.AreEqual(node.AutoFlush, data.AutoFlush); }
internal static bool SaveChanges(TraceSourceSetting setting, ConfigurationElement sourceElement) { TraceSourceData element = (TraceSourceData)sourceElement; element.DefaultLevel = ParseHelper.ParseEnum <SourceLevels>(setting.DefaultLevel, false); element.TraceListeners.Clear(); foreach (string traceListenerName in setting.TraceListeners) { element.TraceListeners.Add(new TraceListenerReferenceData(traceListenerName)); } return(true); }
static public TraceSource GetInstance(String name) { if (_traceSources == null) { _traceSources = new Dictionary <String, TraceSourceData>(); } if (!_traceSources.ContainsKey(name)) { _traceSources[name] = new TraceSourceData(name); } return(_traceSources[name].TS); }
private void BuildTraceSources() { CategoryTraceSourceCollectionNode categoryTracesourceCollectioNode = (CategoryTraceSourceCollectionNode)hierarchy.FindNodeByType(loggingSettingsNode, typeof(CategoryTraceSourceCollectionNode)); if (categoryTracesourceCollectioNode != null) { foreach (CategoryTraceSourceNode traceSourceNode in categoryTracesourceCollectioNode.Nodes) { TraceSourceData traceSourceData = traceSourceNode.TraceSourceData; BuildTraceListenerReferences(traceSourceData, traceSourceNode); loggingSettings.TraceSources.Add(traceSourceData); } } }
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); }
private void AddTraceListeners(ConfigurationNode node, TraceSourceData data) { foreach (TraceListenerReferenceData refData in data.TraceListeners) { TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(refData); foreach (TraceListenerNode listenerNode in listeners.Nodes) { if (listenerNode.Name == referenceNode.Name) { referenceNode.ReferencedTraceListener = listenerNode; } } node.AddNode(referenceNode); } }
private static void CreateTraceSourcePolicies( IPolicyList policyList, string traceSourceName, TraceSourceData traceSourceData, IConfigurationSource configurationSource) { new PolicyBuilder <LogSource, TraceSourceData>(traceSourceName, traceSourceData, c => new LogSource( traceSourceData.Name, Resolve.ReferenceCollection <List <TraceListener>, TraceListener>(from r in traceSourceData.TraceListeners select r.Name), traceSourceData.DefaultLevel, traceSourceData.AutoFlush)) .AddPoliciesToPolicyList(policyList); }
private void AddTraceListeners(ConfigurationNode node, TraceSourceData data) { foreach (TraceListenerReferenceData refData in data.TraceListeners) { TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(refData); foreach(TraceListenerNode listenerNode in listeners.Nodes) { if (listenerNode.Name == referenceNode.Name) { referenceNode.ReferencedTraceListener = listenerNode; } } node.AddNode(referenceNode); } }
public static void GenerateTraceSourceDataWmiObjects(TraceSourceData traceSourceData, ICollection <ConfigurationSetting> wmiSettings, string sourceKind) { string[] referencedTraceListeners = new string[traceSourceData.TraceListeners.Count]; for (int i = 0; i < traceSourceData.TraceListeners.Count; i++) { referencedTraceListeners[i] = traceSourceData.TraceListeners.Get(i).Name; } wmiSettings.Add( new TraceSourceSetting(traceSourceData, traceSourceData.Name, traceSourceData.DefaultLevel.ToString(), referencedTraceListeners, sourceKind)); }
private bool OverrideWithGroupPoliciesForTraceSource( TraceSourceData traceSourceData, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, String sourceKind) { if (readGroupPolicies) { IRegistryKey policyKey = machineKey != null ? machineKey : userKey; if (policyKey != null) { if (policyKey.IsPolicyKey && !policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } try { SourceLevels?defaultLevelOverride = policyKey.GetEnumValue <SourceLevels>(SourceDefaultLevelPropertyName); bool? autoFlushOverride = policyKey.GetBoolValue(SourceAutoFlushPropertyName); // the key where the values for the source listeners are stored // might not exist if no listener is selected traceSourceData.TraceListeners.Clear(); using (IRegistryKey listenersOverrideKey = policyKey.OpenSubKey(SourceTraceListenersPropertyName)) { if (listenersOverrideKey != null) { foreach (String valueName in listenersOverrideKey.GetValueNames()) { traceSourceData.TraceListeners.Add(new TraceListenerReferenceData(valueName)); } } } traceSourceData.DefaultLevel = defaultLevelOverride.Value; traceSourceData.AutoFlush = autoFlushOverride.Value; } catch (RegistryAccessException ex) { LogExceptionWhileOverriding(ex); } } } return(true); }
private void CreateTraceSourceNode(TraceSourceData traceSourceData) { CategoryTraceSourceNode traceSourceNode = new CategoryTraceSourceNode(traceSourceData); foreach (TraceListenerReferenceData traceListener in traceSourceData.TraceListeners) { TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(traceListener); foreach (TraceListenerNode traceListenerNode in listeners.Nodes) { if (traceListenerNode.Name == referenceNode.Name) { referenceNode.ReferencedTraceListener = traceListenerNode; } } traceSourceNode.AddNode(referenceNode); } node.AddNode(traceSourceNode); }
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, objectConfiguration.AutoFlush); InstrumentationAttachmentStrategy instrumentationAttacher = new InstrumentationAttachmentStrategy(); instrumentationAttacher.AttachInstrumentation(createdObject, configurationSource, reflectionCache); return(createdObject); }
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; container.AddExtension(new LoggingBlockExtension()); 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 CreateTraceSourceNode(TraceSourceData traceSourceData) { CategoryTraceSourceNode traceSourceNode = new CategoryTraceSourceNode(traceSourceData); foreach (TraceListenerReferenceData traceListener in traceSourceData.TraceListeners) { TraceListenerReferenceNode referenceNode = new TraceListenerReferenceNode(traceListener); foreach (TraceListenerNode traceListenerNode in listeners.Nodes) { if (traceListenerNode.Name == referenceNode.Name) { referenceNode.ReferencedTraceListener = traceListenerNode; } } traceSourceNode.AddNode(referenceNode); } node.AddNode(traceSourceNode); }
private static TraceSourceData GetCategory(string name, SourceLevels level = SourceLevels.All, params TraceListenerReferenceData[] listenerRefs) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } var category = new TraceSourceData(); if (listenerRefs != null && listenerRefs.Length > 0) { foreach (TraceListenerReferenceData listenerRef in listenerRefs) { category.TraceListeners.Add(listenerRef); } } category.Name = name; category.DefaultLevel = level; return(category); }
public void MachineKeySourceOverrideWithoutListenersSubKeyTakesPrecedenceOverUserKeyOverrides() { TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true); section.TraceSources.Add(sourceData); sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1")); sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2")); MockRegistryKey machineTraceSourcesKey = new MockRegistryKey(false); machineKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, machineTraceSourcesKey); MockRegistryKey machineSource1Key = new MockRegistryKey(false); machineTraceSourcesKey.AddSubKey("source1", machineSource1Key); machineSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing); machineSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false); MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false); userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey); MockRegistryKey userSource1Key = new MockRegistryKey(false); userTraceSourcesKey.AddSubKey("source1", userSource1Key); userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing); userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false); MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false); userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey); userSource1ListenersKey.AddBooleanValue("listener6", true); userSource1ListenersKey.AddBooleanValue("listener7", true); userSource1ListenersKey.AddBooleanValue("listener8", true); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.AreEqual(0, sourceData.TraceListeners.Count); Assert.IsTrue( MockRegistryKey.CheckAllClosed( machineTraceSourcesKey, machineSource1Key, userTraceSourcesKey, userSource1Key, userSource1ListenersKey)); }
public TraceSourceNodeImpl(TraceSourceData data) { Rename(data.Name); SourceLevels = data.DefaultLevel; }
public void TraceSourceTraceListenersAreOverridenIfListenerKeyIsPresentInUserKey() { TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true); section.TraceSources.Add(sourceData); sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1")); sourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2")); MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false); userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey); MockRegistryKey userSource1Key = new MockRegistryKey(false); userTraceSourcesKey.AddSubKey("source1", userSource1Key); userSource1Key.AddEnumValue<SourceLevels>(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.ActivityTracing); userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false); MockRegistryKey userSource1ListenersKey = new MockRegistryKey(false); userSource1Key.AddSubKey(LoggingSettingsManageabilityProvider.SourceTraceListenersPropertyName, userSource1ListenersKey); userSource1ListenersKey.AddBooleanValue("listener3", true); userSource1ListenersKey.AddBooleanValue("listener4", true); userSource1ListenersKey.AddBooleanValue("listener5", true); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.AreEqual(3, sourceData.TraceListeners.Count); Assert.IsNotNull(sourceData.TraceListeners.Get("listener3")); Assert.IsNotNull(sourceData.TraceListeners.Get("listener4")); Assert.IsNotNull(sourceData.TraceListeners.Get("listener5")); Assert.IsTrue(MockRegistryKey.CheckAllClosed(userTraceSourcesKey, userSource1Key, userSource1ListenersKey)); }
public void TraceSourceDefaultLevelIsOverridenFromUserKey() { TraceSourceData sourceData = new TraceSourceData("source1", SourceLevels.Critical, true); section.TraceSources.Add(sourceData); MockRegistryKey userTraceSourcesKey = new MockRegistryKey(false); userKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, userTraceSourcesKey); MockRegistryKey userSource1Key = new MockRegistryKey(false); userTraceSourcesKey.AddSubKey("source1", userSource1Key); userSource1Key.AddStringValue(LoggingSettingsManageabilityProvider.SourceDefaultLevelPropertyName, SourceLevels.Error.ToString()); userSource1Key.AddBooleanValue(LoggingSettingsManageabilityProvider.SourceAutoFlushPropertyName, false); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.AreEqual(SourceLevels.Error, sourceData.DefaultLevel); Assert.AreEqual(false, sourceData.AutoFlush); Assert.IsTrue(MockRegistryKey.CheckAllClosed(userTraceSourcesKey, userSource1Key)); }
public void TraceSourceWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled() { TraceSourceData traceSource1Data = new TraceSourceData("traceSource1", SourceLevels.Error); section.TraceSources.Add(traceSource1Data); TraceSourceData traceSource2Data = new TraceSourceData("traceSource2", SourceLevels.Error); section.TraceSources.Add(traceSource2Data); MockRegistryKey machineTraceSourcesKey = new MockRegistryKey(false); machineKey.AddSubKey(LoggingSettingsManageabilityProvider.CategorySourcesKeyName, machineTraceSourcesKey); MockRegistryKey machineTraceSource2Key = new MockRegistryKey(false); machineTraceSourcesKey.AddSubKey("traceSource2", machineTraceSource2Key); machineTraceSource2Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false); provider.OverrideWithGroupPolicies(section, false, machineKey, userKey); Assert.AreEqual(2, section.TraceSources.Count); Assert.IsNotNull(section.TraceSources.Get("traceSource1")); Assert.IsNotNull(section.TraceSources.Get("traceSource2")); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineTraceSourcesKey, machineTraceSource2Key)); }
public void Setup() { data = new TraceSourceData("source", SourceLevels.Error, true) { TraceListeners = { new TraceListenerReferenceData("listener1"), new TraceListenerReferenceData("listener2") } }; }
public void Setup() { data = new TraceSourceData("source", SourceLevels.Error, true); }