public void CanDeserializeSerializedConfiguration() { string name = "name"; string source = "source"; string log = "log"; string machine = "machine"; string formatter = "formatter"; TraceListenerData data = new FormattedEventLogTraceListenerData(name, source, log, machine, formatter, TraceOptions.Callstack); LoggingSettings settings = new LoggingSettings(); settings.TraceListeners.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.TraceListeners.Count); Assert.IsNotNull(roSettigs.TraceListeners.Get(name)); Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions); Assert.AreSame(typeof(FormattedEventLogTraceListenerData), roSettigs.TraceListeners.Get(name).GetType()); Assert.AreSame(typeof(FormattedEventLogTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType); Assert.AreSame(typeof(FormattedEventLogTraceListener), roSettigs.TraceListeners.Get(name).Type); Assert.AreEqual(formatter, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter); Assert.AreEqual(log, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Log); Assert.AreEqual(machine, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).MachineName); Assert.AreEqual(source, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Source); }
/// <summary> /// Configures the Event Log trace listener with the specified machine name, log name and log source. /// </summary> /// <param name="machineName">The machine name.</param> /// <param name="logName">The event log name.</param> /// <param name="logSource">The event log source name.</param> public void ConfigureEventLogTraceListener(string machineName, string logName, string logSource) { if (this.loggingSettings.TraceListeners.Contains(Resources.EventLogTraceListenerName)) { FormattedEventLogTraceListenerData eventLogData = this.loggingSettings.TraceListeners.Get(Resources.EventLogTraceListenerName) as FormattedEventLogTraceListenerData; if (eventLogData != null) { if (!String.IsNullOrEmpty(machineName)) { eventLogData.MachineName = machineName; } if (!String.IsNullOrEmpty(logName)) { eventLogData.Log = logName; } if (!String.IsNullOrEmpty(logSource)) { eventLogData.Source = logSource; } } } }
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 CanCreateInstanceFromConfigurationFileWithMinimalConfiguration() { LoggingSettings loggingSettings = new LoggingSettings(); loggingSettings.Formatters.Add(new TextFormatterData("formatter", "some template")); FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData(); listenerData.Name = "listener"; listenerData.Type = typeof(FormattedEventLogTraceListener); listenerData.ListenerDataType = typeof(FormattedEventLogTraceListenerData); listenerData.Source = "unknown source"; listenerData.Formatter = "formatter"; loggingSettings.TraceListeners.Add(listenerData); TraceListener listener = GetListener("listener", CommonUtil.SaveSectionsAndGetConfigurationSource(loggingSettings)); Assert.IsNotNull(listener); 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.DefaultLogName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.Log); Assert.AreEqual(FormattedEventLogTraceListener.DefaultMachineName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.MachineName); Assert.AreEqual(castedListener.Formatter.GetType(), typeof(TextFormatter)); Assert.AreEqual("some template", ((TextFormatter)castedListener.Formatter).Template); }
public void CanCreatePoliciesForFormattedEventLogTraceListenerWithFormatter() { FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", CommonUtil.EventLogSourceName, CommonUtil.EventLogName, "machine", "formatter"); listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId; listenerData.Filter = SourceLevels.Error; loggingSettings.TraceListeners.Add(listenerData); FormatterData formatterData = new TextFormatterData("formatter", "template"); loggingSettings.Formatters.Add(formatterData); using (var container = CreateContainer()) { FormattedEventLogTraceListener createdObject = (FormattedEventLogTraceListener)container.Resolve <TraceListener>("listener\u200cimplementation"); Assert.IsNotNull(createdObject); Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions); Assert.IsNotNull(createdObject.Filter); Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter)); Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType); Assert.IsNotNull(createdObject.Formatter); Assert.AreSame(typeof(TextFormatter), createdObject.Formatter.GetType()); Assert.AreEqual("template", ((TextFormatter)createdObject.Formatter).Template); Assert.AreEqual(CommonUtil.EventLogSourceName, ((EventLogTraceListener)createdObject.InnerListener).EventLog.Source); Assert.AreEqual(CommonUtil.EventLogName, ((EventLogTraceListener)createdObject.InnerListener).EventLog.Log); Assert.AreEqual("machine", ((EventLogTraceListener)createdObject.InnerListener).EventLog.MachineName); } }
public void SavesChangesToConfigurationObject() { FormattedEventLogTraceListenerData sourceElement = new FormattedEventLogTraceListenerData(); sourceElement.Filter = SourceLevels.Error; sourceElement.Formatter = "formatter"; sourceElement.Log = "original log"; sourceElement.MachineName = "original machine"; sourceElement.Source = "original source"; sourceElement.TraceOutputOptions = TraceOptions.ProcessId; var settings = new List <ConfigurationSetting>(1); FormattedEventLogTraceListenerDataWmiMapper.GenerateWmiObjects(sourceElement, settings); Assert.AreEqual(1, settings.Count); FormattedEventLogTraceListenerSetting setting = settings[0] as FormattedEventLogTraceListenerSetting; Assert.IsNotNull(setting); setting.Formatter = "updated formatter"; setting.Filter = SourceLevels.All.ToString(); setting.Log = "updated log"; setting.MachineName = "updated machine"; setting.Source = "updated source"; setting.TraceOutputOptions = TraceOptions.ThreadId.ToString(); setting.Commit(); Assert.AreEqual("updated formatter", sourceElement.Formatter); Assert.AreEqual(SourceLevels.All, sourceElement.Filter); Assert.AreEqual("updated log", sourceElement.Log); Assert.AreEqual("updated machine", sourceElement.MachineName); Assert.AreEqual("updated source", sourceElement.Source); Assert.AreEqual(TraceOptions.ThreadId, sourceElement.TraceOutputOptions); }
public void SetUp() { provider = new ConfigurationElementManageabilityProviderWrapper(new FormattedEventLogTraceListenerDataManageabilityProvider()); machineKey = new MockRegistryKey(true); userKey = new MockRegistryKey(true); wmiSettings = new List <ConfigurationSetting>(); configurationObject = new FormattedEventLogTraceListenerData(); }
public void SetUp() { provider = new FormattedEventLogTraceListenerDataManageabilityProvider(); machineKey = new MockRegistryKey(true); machineOptionsKey = new MockRegistryKey(false); userKey = new MockRegistryKey(true); userOptionsKey = new MockRegistryKey(false); configurationObject = new FormattedEventLogTraceListenerData(); }
public void then_file_has_overridden_values() { FileConfigurationSource source = new FileConfigurationSource(TargetFile); LoggingSettings settings = (LoggingSettings)source.GetSection(LoggingSettings.SectionName); FormattedEventLogTraceListenerData traceListener = (FormattedEventLogTraceListenerData)settings.TraceListeners.Get("Event Log Listener"); Assert.AreEqual(TraceOptions.ProcessId, traceListener.TraceOutputOptions); Assert.AreEqual("overridden source", traceListener.Source); Assert.AreEqual("overridden machine", traceListener.MachineName); }
public SendToFormattedEventLogTraceListenerBuilder(ILoggingConfigurationSendTo context, string listenerName) : base(context) { eventLogListener = new FormattedEventLogTraceListenerData { Name = listenerName }; base.AddTraceListenerToSettingsAndCategory(eventLogListener); }
/// <summary> /// Initialize a new instance of the <see cref="FormattedEventLogTraceListenerNode"/> class with a <see cref="FormattedEventLogTraceListenerData"/> instance. /// </summary> /// <param name="traceListenerData">A <see cref="FormattedEventLogTraceListenerData"/> instance.</param> public FormattedEventLogTraceListenerNode(FormattedEventLogTraceListenerData traceListenerData) { if (null == traceListenerData) throw new ArgumentNullException("traceListenerData"); Rename(traceListenerData.Name); TraceOutputOptions = traceListenerData.TraceOutputOptions; this.machineName = traceListenerData.MachineName; this.formatterName = traceListenerData.Formatter; this.log = traceListenerData.Log; this.source = traceListenerData.Source; }
public void ListenerDataIsCreatedCorrectly() { FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", "unknown source", "custom", "machine", "formatter"); Assert.AreSame(typeof(FormattedEventLogTraceListener), listenerData.Type); Assert.AreSame(typeof(FormattedEventLogTraceListenerData), listenerData.ListenerDataType); Assert.AreEqual("listener", listenerData.Name); Assert.AreEqual("unknown source", listenerData.Source); Assert.AreEqual("formatter", listenerData.Formatter); Assert.AreEqual("custom", listenerData.Log); Assert.AreEqual("machine", listenerData.MachineName); }
public static void GenerateWmiObjects(FormattedEventLogTraceListenerData configurationObject, ICollection <ConfigurationSetting> wmiSettings) { wmiSettings.Add( new FormattedEventLogTraceListenerSetting(configurationObject, configurationObject.Name, configurationObject.Source, configurationObject.Log, configurationObject.MachineName, configurationObject.Formatter, configurationObject.TraceOutputOptions.ToString(), configurationObject.Filter.ToString())); }
public FormattedEventLogTraceListenerNode(FormattedEventLogTraceListenerData traceListenerData) { if (null == traceListenerData) { throw new ArgumentNullException("traceListenerData"); } Rename(traceListenerData.Name); TraceOutputOptions = traceListenerData.TraceOutputOptions; this.machineName = traceListenerData.MachineName; this.formatterName = traceListenerData.Formatter; this.log = traceListenerData.Log; this.source = traceListenerData.Source; }
public FormattedEventLogTraceListenerSetting(FormattedEventLogTraceListenerData sourceElement, string name, string source, string log, string machineName, string formatter, string traceOutputOptions, string filter) : base(sourceElement, name, traceOutputOptions, filter) { this.source = source; this.log = log; this.machineName = machineName; this.formatter = formatter; }
public void CanDeserializeSerializedConfigurationWithDefaults() { LoggingSettings rwLoggingSettings = new LoggingSettings(); rwLoggingSettings.TraceListeners.Add(new FormattedEventLogTraceListenerData("listener1", "unknown source", "formatter")); rwLoggingSettings.TraceListeners.Add(new FormattedEventLogTraceListenerData("listener2", "unknown source", "log", "machine", "formatter")); IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = rwLoggingSettings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roLoggingSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(2, roLoggingSettings.TraceListeners.Count); Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener1")); Assert.AreEqual(typeof(FormattedEventLogTraceListenerData), roLoggingSettings.TraceListeners.Get("listener1").GetType()); FormattedEventLogTraceListenerData listener1Data = (FormattedEventLogTraceListenerData)roLoggingSettings.TraceListeners.Get("listener1"); Assert.AreEqual("listener1", listener1Data.Name); Assert.AreEqual("unknown source", listener1Data.Source); Assert.AreEqual("formatter", listener1Data.Formatter); Assert.AreEqual(typeof(FormattedEventLogTraceListener), listener1Data.Type); Assert.AreEqual(typeof(FormattedEventLogTraceListenerData), listener1Data.ListenerDataType); Assert.AreEqual(FormattedEventLogTraceListener.DefaultLogName, listener1Data.Log); Assert.AreEqual(FormattedEventLogTraceListener.DefaultMachineName, listener1Data.MachineName); Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener2")); Assert.AreEqual(typeof(FormattedEventLogTraceListenerData), roLoggingSettings.TraceListeners.Get("listener2").GetType()); FormattedEventLogTraceListenerData listener2Data = (FormattedEventLogTraceListenerData)roLoggingSettings.TraceListeners.Get("listener2"); Assert.AreEqual("listener2", listener2Data.Name); Assert.AreEqual("unknown source", listener2Data.Source); Assert.AreEqual("formatter", listener2Data.Formatter); Assert.AreEqual(typeof(FormattedEventLogTraceListener), listener2Data.Type); Assert.AreEqual(typeof(FormattedEventLogTraceListenerData), listener2Data.ListenerDataType); Assert.AreEqual("log", listener2Data.Log); Assert.AreEqual("machine", listener2Data.MachineName); }
public void FormattedEventLogTraceListenerNodeDataTest() { string name = "some name"; string source = "some source"; string log = "some log"; string machineName = "some machine"; FormattedEventLogTraceListenerData formattedEventLogTraceListenerData = new FormattedEventLogTraceListenerData(); formattedEventLogTraceListenerData.Name = name; formattedEventLogTraceListenerData.Log = log; formattedEventLogTraceListenerData.Source = source; formattedEventLogTraceListenerData.MachineName = machineName; FormattedEventLogTraceListenerNode formattedEventLogTraceListenerNode = new FormattedEventLogTraceListenerNode(formattedEventLogTraceListenerData); ApplicationNode.AddNode(formattedEventLogTraceListenerNode); Assert.AreEqual(name, formattedEventLogTraceListenerNode.Name); Assert.AreEqual(log, formattedEventLogTraceListenerNode.Log); Assert.AreEqual(source, formattedEventLogTraceListenerNode.Source); Assert.AreEqual(machineName, formattedEventLogTraceListenerNode.MachineName); }
public void CanCreateInstanceFromGivenConfiguration() { FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", "unknown source", "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(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 CanCreatePoliciesForFormattedEventLogTraceListener() { FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener", CommonUtil.EventLogSourceName, CommonUtil.EventLogName, "machine", ""); listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId; listenerData.Filter = SourceLevels.Error; loggingSettings.TraceListeners.Add(listenerData); container.AddExtension(new LoggingBlockExtension()); FormattedEventLogTraceListener createdObject = (FormattedEventLogTraceListener)container.Resolve <TraceListener>("listener"); Assert.IsNotNull(createdObject); Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions); Assert.IsNotNull(createdObject.Filter); Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter)); Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType); Assert.IsNull(createdObject.Formatter); Assert.AreEqual(CommonUtil.EventLogSourceName, ((EventLogTraceListener)createdObject.SlaveListener).EventLog.Source); Assert.AreEqual(CommonUtil.EventLogName, ((EventLogTraceListener)createdObject.SlaveListener).EventLog.Log); Assert.AreEqual("machine", ((EventLogTraceListener)createdObject.SlaveListener).EventLog.MachineName); }
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 = GetListener("listener\u200cimplementation", helper.configurationSource); Assert.IsNotNull(listener); Assert.AreEqual("listener\u200cimplementation", 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.DefaultLogName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.Log); Assert.AreEqual(FormattedEventLogTraceListener.DefaultMachineName, ((EventLogTraceListener)castedListener.InnerListener).EventLog.MachineName); Assert.AreEqual(castedListener.Formatter.GetType(), typeof(TextFormatter)); Assert.AreEqual("foobar template", ((TextFormatter)castedListener.Formatter).Template); }
private void ApplyDefaultTraceListener() { if (!this.loggingSettings.TraceListeners.Contains(Resources.FormattedDebugTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.FormattedDebugTraceListenerName)) { CustomTraceListenerData listenerData = new CustomTraceListenerData(); listenerData.Formatter = Resources.TraceLogTextFormatterName; listenerData.Type = typeof(FormattedDebugTraceListener); listenerData.Name = Resources.FormattedDebugTraceListenerName; listenerData.TraceOutputOptions = TraceOptions.None; listenerData.Filter = SourceLevels.All; this.loggingSettings.TraceListeners.Add(listenerData); } } } if (!this.loggingSettings.TraceListeners.Contains(Resources.TraceLogTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.TraceLogTraceListenerName)) { CustomTraceListenerData listenerData = new CustomTraceListenerData(); listenerData.Formatter = Resources.TraceLogTextFormatterName; listenerData.Type = typeof(FormattedTextWriterTraceListener); listenerData.Name = Resources.TraceLogTraceListenerName; listenerData.TraceOutputOptions = TraceOptions.None; listenerData.Filter = SourceLevels.All; this.loggingSettings.TraceListeners.Add(listenerData); } } } if (!this.loggingSettings.TraceListeners.Contains(Resources.EventLogTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.EventLogTraceListenerName)) { FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData(); listenerData.Formatter = Resources.EventLogTextFormatterName; listenerData.Type = typeof(FormattedEventLogTraceListener); listenerData.Name = Resources.EventLogTraceListenerName; listenerData.MachineName = "."; listenerData.Source = AppDomain.CurrentDomain.SetupInformation.ApplicationName; listenerData.Log = Resources.DefaultEventLogTraceListenerLogName; this.loggingSettings.TraceListeners.Add(listenerData); } } } if (!this.loggingSettings.TraceListeners.Contains(Resources.RollingFlatFileTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.RollingFlatFileTraceListenerName)) { RollingFlatFileTraceListenerData listenerData = new RollingFlatFileTraceListenerData(); listenerData.Name = Resources.RollingFlatFileTraceListenerName; listenerData.Formatter = Resources.TraceLogTextFormatterName; listenerData.FileName = Path.ChangeExtension(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, ".log"); listenerData.Footer = String.Empty; listenerData.Header = String.Empty; listenerData.TimeStampPattern = Resources.RollingFlatFileTraceListenerTimeStampPattern; listenerData.MaxArchivedFiles = 10; listenerData.RollFileExistsBehavior = RollFileExistsBehavior.Increment; listenerData.RollSizeKB = 10240; this.loggingSettings.TraceListeners.Add(listenerData); } } } if (!this.loggingSettings.TraceListeners.Contains(Resources.EmailTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.EmailTraceListenerName)) { EmailTraceListenerData listenerData = new EmailTraceListenerData(); listenerData.Name = Resources.EmailTraceListenerName; listenerData.AuthenticationMode = EmailAuthenticationMode.UserNameAndPassword; listenerData.Formatter = Resources.EventLogTextFormatterName; listenerData.SmtpPort = 25; this.loggingSettings.TraceListeners.Add(listenerData); } } } if (!this.loggingSettings.TraceListeners.Contains(Resources.FormattedDatabaseTraceListenerName)) { lock (this.listenerLock) { if (!this.loggingSettings.TraceListeners.Contains(Resources.FormattedDatabaseTraceListenerName)) { FormattedDatabaseTraceListenerData listenerData = new FormattedDatabaseTraceListenerData(); listenerData.Name = Resources.FormattedDatabaseTraceListenerName; listenerData.AddCategoryStoredProcName = SqlCommandResources.AddCategoryStoredProcName; listenerData.WriteLogStoredProcName = SqlCommandResources.WriteLogStoredProcName; this.loggingSettings.TraceListeners.Add(listenerData); } } } }
public void WhenCreatingInstanceUsingDefaultContructor_ThenListenerDataTypeIsSet() { var listener = new FormattedEventLogTraceListenerData(); Assert.AreEqual(typeof(FormattedEventLogTraceListenerData), listener.ListenerDataType); }
public void RegisteredTraceListenerDataProviderIsCalledWithNoOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(FormattedEventLogTraceListenerData), registeredProvider); provider = new LoggingSettingsManageabilityProvider(subProviders); FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("name", "source", "formatter"); section.TraceListeners.Add(listenerData); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(listenerData, registeredProvider.LastConfigurationObject); Assert.AreEqual(null, registeredProvider.machineKey); Assert.AreEqual(null, registeredProvider.userKey); }
public void RegisteredListenerDataProviderIsCalledWithCorrectOverrides() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(FormattedEventLogTraceListenerData), registeredProvider); provider = new LoggingSettingsManageabilityProvider(subProviders); FormattedEventLogTraceListenerData listenerData = new FormattedEventLogTraceListenerData("listener1", "source", "formatter"); section.TraceListeners.Add(listenerData); MockRegistryKey machineListenersKey = new MockRegistryKey(false); machineKey.AddSubKey(LoggingSettingsManageabilityProvider.TraceListenersKeyName, machineListenersKey); MockRegistryKey machineListenerKey = new MockRegistryKey(false); machineListenersKey.AddSubKey("listener1", machineListenerKey); MockRegistryKey machineOtherListenerKey = new MockRegistryKey(false); machineListenersKey.AddSubKey("listener2", machineOtherListenerKey); MockRegistryKey userListenersKey = new MockRegistryKey(false); userKey.AddSubKey(LoggingSettingsManageabilityProvider.TraceListenersKeyName, userListenersKey); MockRegistryKey userListenerKey = new MockRegistryKey(false); userListenersKey.AddSubKey("listener1", userListenerKey); MockRegistryKey userOtherListenerKey = new MockRegistryKey(false); userListenersKey.AddSubKey("listener2", userOtherListenerKey); provider.OverrideWithGroupPolicies(section, true, machineKey, userKey); Assert.IsTrue(registeredProvider.called); Assert.AreSame(listenerData, registeredProvider.LastConfigurationObject); Assert.AreSame(machineListenerKey, registeredProvider.machineKey); Assert.AreSame(userListenerKey, registeredProvider.userKey); Assert.IsTrue( MockRegistryKey.CheckAllClosed(machineListenersKey, machineListenerKey, machineOtherListenerKey, userListenersKey, userListenerKey, userOtherListenerKey)); }