/// <summary> /// Creates a new <see cref="SqlTraceListener"/> using the specified settings name /// </summary> /// <param name="settingsName">the name of the SqlTraceListener settings to use from configuration</param> public SqlTraceListener(string settingsName) : base(settingsName) { UkadcDiagnosticsSection ukadcDiagnosticsSection = UkadcDiagnosticsSection.ReadConfigSection(); SqlTraceListenerElement sqlTraceListenerElement = ukadcDiagnosticsSection.SqlTraceListeners[settingsName]; if (null == sqlTraceListenerElement) { throw new ConfigurationErrorsException( string.Format(CultureInfo.CurrentCulture, Resources.SqlTraceListenerConfigError, settingsName)); } string connectionString = ConfigurationManager.ConnectionStrings[sqlTraceListenerElement.ConnectionStringName].ConnectionString; // use default data adapter IDataAccessAdapter adapter = new SqlDataAccessAdapter(); adapter.Initialize( connectionString, sqlTraceListenerElement.CommandText, sqlTraceListenerElement.CommandType); DataAccessAdapter = adapter; IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>(); foreach (ParameterElement param in sqlTraceListenerElement.Parameters) { PropertyReader propertyReader = readerFactory.Create(param); this.Parameters.Add( new SqlTraceParameter(param.Name, propertyReader, param.CallToString)); } }
private void LoadConfiguredTokens() { // We need to load the tokens from configuration the first time this is accessed. UkadcDiagnosticsSection section; if (UkadcDiagnosticsSection.TryReadConfigSection(out section)) { if (section.Tokens != null) { for (int i = 0; i < section.Tokens.Count; i++) { TokenElement token = section.Tokens[i]; AddToken(token.Name, ReadConfigToken(token)); } } } }
/// <summary> /// Creates a new <see cref="MultiFilter"/> from configuration using the group name in configuration /// </summary> /// <param name="groupName">The name of the group in configuration</param> public MultiFilter(string groupName) { if (string.IsNullOrEmpty(groupName)) { throw new ArgumentNullException("groupName"); } UkadcDiagnosticsSection multiFilterSection = UkadcDiagnosticsSection.ReadConfigSection(); FilterGroupElement filterGroupConfigElement = multiFilterSection.FilterGroups[groupName]; if (null == filterGroupConfigElement) { throw new ConfigurationErrorsException( string.Format(CultureInfo.CurrentCulture, Resources.MultiFilterGroupError, groupName)); } _filterGroup = new MultiFilterGroup(filterGroupConfigElement); Validate(); }
/// <summary> /// Creates a propertyFilter using configuration, looking for a propertyFilter element with the specified name /// </summary> /// <param name="propertyFilterName">Name of the propertyFilter element to use for configuration</param> /// <exception cref="System.ArgumentNullException">Thrown if the propertyFilterName argument is null</exception> public PropertyFilter(string propertyFilterName) { if (string.IsNullOrEmpty(propertyFilterName)) { throw new ArgumentNullException("propertyFilterName"); } UkadcDiagnosticsSection section = UkadcDiagnosticsSection.ReadConfigSection(); PropertyFilterElement element = section.PropertyFilters[propertyFilterName]; if (element == null) { throw new ConfigurationErrorsException( string.Format(CultureInfo.CurrentCulture, Resources.PropertyFilterNotFound, propertyFilterName)); } PropertyReader = DefaultServiceLocator.GetService <IPropertyReaderFactory>().Create(element); Initialize(element.Value, element.Operation, PropertyReader, element.DefaultEvaluation); }
/// <summary> /// Configure the trace listener based on the named configuration section /// </summary> /// <param name="sectionName">The name of the config section</param> public SmtpTraceListener(string sectionName) : base("SmtpTraceListener") { UkadcDiagnosticsSection config = UkadcDiagnosticsSection.ReadConfigSection(); SmtpTraceListenerElement smtpTraceListenerElement = config.SmtpTraceListeners[sectionName]; if (null == smtpTraceListenerElement) { throw new ConfigurationErrorsException( string.Format(CultureInfo.CurrentCulture, Resources.SmtpTraceListenerConfigError, sectionName)); } InternalConfigure( DefaultServiceLocator.GetService <IPropertyReaderFactory>(), new SmtpService(), smtpTraceListenerElement.Host, smtpTraceListenerElement.Port, smtpTraceListenerElement.Username, smtpTraceListenerElement.Password, smtpTraceListenerElement.To, smtpTraceListenerElement.From, smtpTraceListenerElement.Subject, smtpTraceListenerElement.Body); }