#region Copyright & License // // Copyright 2001-2005 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #endregion // .NET Compact Framework 1.0 has no support for reading assembly attributes #if !NETCF using System; using System.Reflection; using log4net.Util; using log4net.Repository; using log4net.Core; namespace log4net.Config { /// /// Assembly level attribute to configure the . /// /// /// /// This attribute may only be used at the assembly scope and can only /// be used once per assembly. /// /// /// Use this attribute to configure the /// without calling one of the /// methods. /// /// /// Nicko Cadell [AttributeUsage(AttributeTargets.Assembly)] [Serializable] public sealed class SecurityContextProviderAttribute : ConfiguratorAttribute { #region Constructor /// /// Construct provider attribute with type specified /// /// the type of the provider to use /// /// /// The provider specified must subclass the /// class. /// /// public SecurityContextProviderAttribute(Type providerType) : base(100) /* configurator priority 100 to execute before the XmlConfigurator */ { m_providerType = providerType; } #endregion #region Public Instance Properties /// /// Gets or sets the type of the provider to use. /// /// /// the type of the provider to use. /// /// /// /// The provider specified must subclass the /// class. /// /// public Type ProviderType { get { return m_providerType; } set { m_providerType = value; } } #endregion Public Instance Properties #region Override ConfiguratorAttribute /// /// Configures the SecurityContextProvider /// /// The assembly that this attribute was defined on. /// The repository to configure. /// /// /// Creates a provider instance from the specified. /// Sets this as the default security context provider . /// /// override public void Configure(Assembly sourceAssembly, ILoggerRepository targetRepository) { if (m_providerType == null) { LogLog.Error("SecurityContextProviderAttribute: Attribute specified on assembly ["+sourceAssembly.FullName+"] with null ProviderType."); } else { LogLog.Debug("SecurityContextProviderAttribute: Creating provider of type ["+ m_providerType.FullName +"]"); SecurityContextProvider provider = Activator.CreateInstance(m_providerType) as SecurityContextProvider; if (provider == null) { LogLog.Error("SecurityContextProviderAttribute: Failed to create SecurityContextProvider instance of type ["+m_providerType.Name+"]."); } else { SecurityContextProvider.DefaultProvider = provider; } } } #endregion #region Private Instance Fields private Type m_providerType = null; #endregion Private Instance Fields } } #endif // !NETCF