📄 loggermanager.cs
字号:
/// </para>
/// </remarks>
public static void ResetConfiguration(Assembly repositoryAssembly)
{
if (repositoryAssembly == null)
{
throw new ArgumentNullException("repositoryAssembly");
}
RepositorySelector.GetRepository(repositoryAssembly).ResetConfiguration();
}
/// <summary>
/// Creates a repository with the specified name.
/// </summary>
/// <param name="repository">The name of the repository, this must be unique amongst repositories.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// Creates the default type of <see cref="ILoggerRepository"/> which is a
/// <see cref="log4net.Repository.Hierarchy.Hierarchy"/> object.
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <exception cref="LogException">The specified repository already exists.</exception>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository)
{
return CreateRepository(repository);
}
/// <summary>
/// Creates a repository with the specified name.
/// </summary>
/// <param name="repository">The name of the repository, this must be unique amongst repositories.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// Creates the default type of <see cref="ILoggerRepository"/> which is a
/// <see cref="log4net.Repository.Hierarchy.Hierarchy"/> object.
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An <see cref="Exception"/> will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <exception cref="LogException">The specified repository already exists.</exception>
public static ILoggerRepository CreateRepository(string repository)
{
if (repository == null)
{
throw new ArgumentNullException("repository");
}
return RepositorySelector.CreateRepository(repository, null);
}
/// <summary>
/// Creates a repository with the specified name and repository type.
/// </summary>
/// <param name="repository">The name of the repository, this must be unique to the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An Exception will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <exception cref="LogException">The specified repository already exists.</exception>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(string repository, Type repositoryType)
{
return CreateRepository(repository, repositoryType);
}
/// <summary>
/// Creates a repository with the specified name and repository type.
/// </summary>
/// <param name="repository">The name of the repository, this must be unique to the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// The <paramref name="repository"/> name must be unique. Repositories cannot be redefined.
/// An Exception will be thrown if the repository already exists.
/// </para>
/// </remarks>
/// <exception cref="LogException">The specified repository already exists.</exception>
public static ILoggerRepository CreateRepository(string repository, Type repositoryType)
{
if (repository == null)
{
throw new ArgumentNullException("repository");
}
if (repositoryType == null)
{
throw new ArgumentNullException("repositoryType");
}
return RepositorySelector.CreateRepository(repository, repositoryType);
}
/// <summary>
/// Creates a repository for the specified assembly and repository type.
/// </summary>
/// <param name="repositoryAssembly">The assembly to use to get the name of the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// <b>CreateDomain is obsolete. Use CreateRepository instead of CreateDomain.</b>
/// </para>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
[Obsolete("Use CreateRepository instead of CreateDomain")]
public static ILoggerRepository CreateDomain(Assembly repositoryAssembly, Type repositoryType)
{
return CreateRepository(repositoryAssembly, repositoryType);
}
/// <summary>
/// Creates a repository for the specified assembly and repository type.
/// </summary>
/// <param name="repositoryAssembly">The assembly to use to get the name of the repository.</param>
/// <param name="repositoryType">A <see cref="Type"/> that implements <see cref="ILoggerRepository"/>
/// and has a no arg constructor. An instance of this type will be created to act
/// as the <see cref="ILoggerRepository"/> for the repository specified.</param>
/// <returns>The <see cref="ILoggerRepository"/> created for the repository.</returns>
/// <remarks>
/// <para>
/// The <see cref="ILoggerRepository"/> created will be associated with the repository
/// specified such that a call to <see cref="GetRepository(Assembly)"/> with the
/// same assembly specified will return the same repository instance.
/// </para>
/// </remarks>
public static ILoggerRepository CreateRepository(Assembly repositoryAssembly, Type repositoryType)
{
if (repositoryAssembly == null)
{
throw new ArgumentNullException("repositoryAssembly");
}
if (repositoryType == null)
{
throw new ArgumentNullException("repositoryType");
}
return RepositorySelector.CreateRepository(repositoryAssembly, repositoryType);
}
/// <summary>
/// Gets an array of all currently defined repositories.
/// </summary>
/// <returns>An array of all the known <see cref="ILoggerRepository"/> objects.</returns>
/// <remarks>
/// <para>
/// Gets an array of all currently defined repositories.
/// </para>
/// </remarks>
public static ILoggerRepository[] GetAllRepositories()
{
return RepositorySelector.GetAllRepositories();
}
/// <summary>
/// Gets or sets the repository selector used by the <see cref="LogManager" />.
/// </summary>
/// <value>
/// The repository selector used by the <see cref="LogManager" />.
/// </value>
/// <remarks>
/// <para>
/// The repository selector (<see cref="IRepositorySelector"/>) is used by
/// the <see cref="LogManager"/> to create and select repositories
/// (<see cref="ILoggerRepository"/>).
/// </para>
/// <para>
/// The caller to <see cref="LogManager"/> supplies either a string name
/// or an assembly (if not supplied the assembly is inferred using
/// <see cref="Assembly.GetCallingAssembly()"/>).
/// </para>
/// <para>
/// This context is used by the selector to lookup a specific repository.
/// </para>
/// <para>
/// For the full .NET Framework, the default repository is <c>DefaultRepositorySelector</c>;
/// for the .NET Compact Framework <c>CompactRepositorySelector</c> is the default
/// repository.
/// </para>
/// </remarks>
public static IRepositorySelector RepositorySelector
{
get { return s_repositorySelector; }
set { s_repositorySelector = value; }
}
#endregion Public Static Methods
#region Private Static Methods
/// <summary>
/// Internal method to get pertinent version info.
/// </summary>
/// <returns>A string of version info.</returns>
private static string GetVersionInfo()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
// Grab the currently executing assembly
Assembly myAssembly = Assembly.GetExecutingAssembly();
// Build Up message
sb.Append("log4net assembly [").Append(myAssembly.FullName).Append("]. ");
sb.Append("Loaded from [").Append(SystemInfo.AssemblyLocationInfo(myAssembly)).Append("]. ");
sb.Append("(.NET Runtime [").Append(Environment.Version.ToString()).Append("]");
#if (!SSCLI)
sb.Append(" on ").Append(Environment.OSVersion.ToString());
#endif
sb.Append(")");
return sb.ToString();
}
#if (!NETCF)
/// <summary>
/// Called when the <see cref="AppDomain.DomainUnload"/> event fires
/// </summary>
/// <param name="sender">the <see cref="AppDomain"/> that is exiting</param>
/// <param name="e">null</param>
/// <remarks>
/// <para>
/// Called when the <see cref="AppDomain.DomainUnload"/> event fires.
/// </para>
/// <para>
/// When the event is triggered the log4net system is <see cref="Shutdown()"/>.
/// </para>
/// </remarks>
private static void OnDomainUnload(object sender, EventArgs e)
{
Shutdown();
}
/// <summary>
/// Called when the <see cref="AppDomain.ProcessExit"/> event fires
/// </summary>
/// <param name="sender">the <see cref="AppDomain"/> that is exiting</param>
/// <param name="e">null</param>
/// <remarks>
/// <para>
/// Called when the <see cref="AppDomain.ProcessExit"/> event fires.
/// </para>
/// <para>
/// When the event is triggered the log4net system is <see cref="Shutdown()"/>.
/// </para>
/// </remarks>
private static void OnProcessExit(object sender, EventArgs e)
{
Shutdown();
}
#endif
#endregion Private Static Methods
#region Private Static Fields
/// <summary>
/// Initialize the default repository selector
/// </summary>
private static IRepositorySelector s_repositorySelector;
#endregion Private Static Fields
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -