#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to you 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 .
///
///
public override void Configure(Assembly sourceAssembly, ILoggerRepository targetRepository)
{
if (m_providerType == null)
{
LogLog.Error(declaringType, "Attribute specified on assembly ["+sourceAssembly.FullName+"] with null ProviderType.");
}
else
{
LogLog.Debug(declaringType, "Creating provider of type ["+ m_providerType.FullName +"]");
SecurityContextProvider provider = Activator.CreateInstance(m_providerType) as SecurityContextProvider;
if (provider == null)
{
LogLog.Error(declaringType, "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
#region Private Static Fields
///
/// The fully qualified type of the SecurityContextProviderAttribute class.
///
///
/// Used by the internal logger to record the Type of the
/// log message.
///
private static readonly Type declaringType = typeof(SecurityContextProviderAttribute);
#endregion Private Static Fields
}
}
#endif // !NETCF