diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-12 08:40:50 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-12 08:42:14 -0800 |
commit | af21cdaf77ca72f54e04f22268b740ce262582fa (patch) | |
tree | 9b158e3bff1f56264bccb9e45c8b807816beece6 /src/DotNetOpenAuth.Core/Logger.cs | |
parent | a73f2a4830aaa2afcb3f13da2206d9b011dad7fb (diff) | |
download | DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.zip DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.tar.gz DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.tar.bz2 |
Renamed assembly DotNetOpenAuth.Messaging(.UI) to DotNetOpenAuth.Core(.UI)
Diffstat (limited to 'src/DotNetOpenAuth.Core/Logger.cs')
-rw-r--r-- | src/DotNetOpenAuth.Core/Logger.cs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Logger.cs b/src/DotNetOpenAuth.Core/Logger.cs new file mode 100644 index 0000000..c9283cd --- /dev/null +++ b/src/DotNetOpenAuth.Core/Logger.cs @@ -0,0 +1,184 @@ +//----------------------------------------------------------------------- +// <copyright file="Logger.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth { + using System; + using System.Diagnostics.Contracts; + using System.Globalization; + using DotNetOpenAuth.Loggers; + using DotNetOpenAuth.Messaging; + using log4net.Core; + + /// <summary> + /// A general logger for the entire DotNetOpenAuth library. + /// </summary> + /// <remarks> + /// Because this logger is intended for use with non-localized strings, the + /// overloads that take <see cref="CultureInfo"/> have been removed, and + /// <see cref="CultureInfo.InvariantCulture"/> is used implicitly. + /// </remarks> + internal static partial class Logger { + #region Category-specific loggers + + /// <summary> + /// The <see cref="ILog"/> instance that is to be used + /// by this static Logger for the duration of the appdomain. + /// </summary> + private static readonly ILog library = CreateWithBanner("DotNetOpenAuth"); + + /// <summary> + /// Backing field for the <see cref="Yadis"/> property. + /// </summary> + private static readonly ILog yadis = Create("DotNetOpenAuth.Yadis"); + + /// <summary> + /// Backing field for the <see cref="Messaging"/> property. + /// </summary> + private static readonly ILog messaging = Create("DotNetOpenAuth.Messaging"); + + /// <summary> + /// Backing field for the <see cref="Channel"/> property. + /// </summary> + private static readonly ILog channel = Create("DotNetOpenAuth.Messaging.Channel"); + + /// <summary> + /// Backing field for the <see cref="Bindings"/> property. + /// </summary> + private static readonly ILog bindings = Create("DotNetOpenAuth.Messaging.Bindings"); + + /// <summary> + /// Backing field for the <see cref="Signatures"/> property. + /// </summary> + private static readonly ILog signatures = Create("DotNetOpenAuth.Messaging.Bindings.Signatures"); + + /// <summary> + /// Backing field for the <see cref="Http"/> property. + /// </summary> + private static readonly ILog http = Create("DotNetOpenAuth.Http"); + + /// <summary> + /// Backing field for the <see cref="Controls"/> property. + /// </summary> + private static readonly ILog controls = Create("DotNetOpenAuth.Controls"); + + /// <summary> + /// Backing field for the <see cref="OpenId"/> property. + /// </summary> + private static readonly ILog openId = Create("DotNetOpenAuth.OpenId"); + + /// <summary> + /// Backing field for the <see cref="OAuth"/> property. + /// </summary> + private static readonly ILog oauth = Create("DotNetOpenAuth.OAuth"); + + /// <summary> + /// Backing field for the <see cref="InfoCard"/> property. + /// </summary> + private static readonly ILog infocard = Create("DotNetOpenAuth.InfoCard"); + + /// <summary> + /// Gets the logger for general library logging. + /// </summary> + internal static ILog Library { get { return library; } } + + /// <summary> + /// Gets the logger for service discovery and selection events. + /// </summary> + internal static ILog Yadis { get { return yadis; } } + + /// <summary> + /// Gets the logger for Messaging events. + /// </summary> + internal static ILog Messaging { get { return messaging; } } + + /// <summary> + /// Gets the logger for Channel events. + /// </summary> + internal static ILog Channel { get { return channel; } } + + /// <summary> + /// Gets the logger for binding elements and binding-element related events on the channel. + /// </summary> + internal static ILog Bindings { get { return bindings; } } + + /// <summary> + /// Gets the logger specifically used for logging verbose text on everything about the signing process. + /// </summary> + internal static ILog Signatures { get { return signatures; } } + + /// <summary> + /// Gets the logger for HTTP-level events. + /// </summary> + internal static ILog Http { get { return http; } } + + /// <summary> + /// Gets the logger for events logged by ASP.NET controls. + /// </summary> + internal static ILog Controls { get { return controls; } } + + /// <summary> + /// Gets the logger for high-level OpenID events. + /// </summary> + internal static ILog OpenId { get { return openId; } } + + /// <summary> + /// Gets the logger for high-level OAuth events. + /// </summary> + internal static ILog OAuth { get { return oauth; } } + + /// <summary> + /// Gets the logger for high-level InfoCard events. + /// </summary> + internal static ILog InfoCard { get { return infocard; } } + + #endregion + + /// <summary> + /// Creates an additional logger on demand for a subsection of the application. + /// </summary> + /// <param name="name">A name that will be included in the log file.</param> + /// <returns>The <see cref="ILog"/> instance created with the given name.</returns> + internal static ILog Create(string name) { + Requires.NotNullOrEmpty(name, "name"); + return InitializeFacade(name); + } + + /// <summary> + /// Creates the main logger for the library, and emits an INFO message + /// that is the name and version of the library. + /// </summary> + /// <param name="name">A name that will be included in the log file.</param> + /// <returns>The <see cref="ILog"/> instance created with the given name.</returns> + internal static ILog CreateWithBanner(string name) { + Requires.NotNullOrEmpty(name, "name"); + ILog log = Create(name); + log.Info(Util.LibraryVersion); + return log; + } + + /// <summary> + /// Creates an additional logger on demand for a subsection of the application. + /// </summary> + /// <param name="type">A type whose full name that will be included in the log file.</param> + /// <returns>The <see cref="ILog"/> instance created with the given type name.</returns> + internal static ILog Create(Type type) { + Requires.NotNull(type, "type"); + + return Create(type.FullName); + } + + /// <summary> + /// Discovers the presence of Log4net.dll and other logging mechanisms + /// and returns the best available logger. + /// </summary> + /// <param name="name">The name of the log to initialize.</param> + /// <returns>The <see cref="ILog"/> instance of the logger to use.</returns> + private static ILog InitializeFacade(string name) { + ILog result = Log4NetLogger.Initialize(name) ?? TraceLogger.Initialize(name) ?? NoOpLogger.Initialize(); + return result; + } + } +} |