/// <summary>Initializes the provider.</summary> /// <param name="name">The friendly name of the provider.</param> /// <param name="config">A collection of the name/value pairs representing the provider-specific /// attributes specified in the configuration for this provider.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="config"/> is null.</exception> /// <exception cref="ArgumentException">Thrown when the name of the provider has a length of zero.</exception> /// <exception cref="InvalidOperationException">Thrown when an attempt is made to call Initialize on a /// provider after the provider has already been initialized.</exception> /// <exception cref="ProviderException">Thrown when the <paramref name="config"/> contains /// unrecognized attributes or when the connectionStringName attribute is not configured properly.</exception> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } LoggingHelper.SetDescriptionWhenMissing(config, "ASP.NET SQL logging provider"); // Retrieve and remove values from config. We do this before calling base.Initialize(), // because the base class checks for unrecognized attributes. bool logQueryString = GetLogQueryStringFromConfig(name, config); bool logFormData = GetLogFormDataFromConfig(name, config); UserIdentityRetrievalType retrievalType = GetRetrievalTypeFromConfig(name, config); string applicationName = GetApplicationNameFromConfig(name, config); // Then call initialize (base.Initialize checks for unrecognized attributes) base.Initialize(name, config); // Set fields after base.Initialize (this prevents the provider from being altered by calling // Initialize a second time). this.logQueryString = logQueryString; this.logFormData = logFormData; this.retrievalType = retrievalType; this.applicationName = applicationName; }
private static UserIdentityRetrievalType GetRetrievalTypeFromConfig(string providerName, NameValueCollection config) { const string UserNameRetrievalTypeAttribute = "userNameRetrievalType"; string userNameRetrievalType = config[UserNameRetrievalTypeAttribute]; // Throw exception when no userNameRetrievalType is provided if (string.IsNullOrEmpty(userNameRetrievalType)) { throw new ProviderException(SR.MissingUserNameRetrievalTypeAttributeInConfig(providerName)); } UserIdentityRetrievalType retrievalType; try { retrievalType = (UserIdentityRetrievalType) Enum.Parse(typeof(UserIdentityRetrievalType), userNameRetrievalType, true); } catch (ArgumentException) { throw new ProviderException(SR.InvalidUseNameRetrievalTypeAttributeInConfig(providerName)); } // Remove this attribute from the configuration. This way the provider can spot unrecognized // attributes after the initialization process. config.Remove(UserNameRetrievalTypeAttribute); return(retrievalType); }
/// <summary> /// Initializes a new instance of the <see cref="AspNetSqlLoggingProvider"/> class. /// </summary> /// <param name="threshold">The <see cref="LoggingEventType"/> logging threshold. The threshold limits /// the number of event logged. <see cref="LoggingProviderBase.Threshold">Threshold</see> for more /// information.</param> /// <param name="configuration">The configuration that initializes this provider.</param> /// <param name="connectionString">The connection string.</param> /// <param name="fallbackProvider">The optional fallback provider.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="connectionString"/> or the /// <paramref name="configuration"/> are null references (Nothing in VB).</exception> /// <exception cref="ArgumentException">Thrown when the <paramref name="connectionString"/> is an /// empty string.</exception> public AspNetSqlLoggingProvider(LoggingEventType threshold, AspNetSqlLoggingProviderConfiguration configuration, string connectionString, LoggingProviderBase fallbackProvider) : base(threshold, connectionString, fallbackProvider) { if (configuration == null) { throw new ArgumentNullException("configuration"); } // We don't have to validate the configuration properties, because the configuration already did // this itself. this.logQueryString = configuration.LogQueryString; this.logFormData = configuration.LogFormData; this.applicationName = configuration.ApplicationName; this.retrievalType = configuration.RetrievalType; }