diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-09 08:15:28 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-09 08:15:28 -0700 |
commit | 4d3d57f1951644de1b11842008d153bad30ef009 (patch) | |
tree | 62dcd32a5448ec9f0696aa59cf36f5f609e6b986 | |
parent | 871dc36214618e53ab682ab71413f925a78b27f5 (diff) | |
parent | 69c93e649dcce69a91d8d5696015e00ee9518e17 (diff) | |
download | DotNetOpenAuth-4d3d57f1951644de1b11842008d153bad30ef009.zip DotNetOpenAuth-4d3d57f1951644de1b11842008d153bad30ef009.tar.gz DotNetOpenAuth-4d3d57f1951644de1b11842008d153bad30ef009.tar.bz2 |
Merge branch 'starterkit'
Conflicts:
src/DotNetOAuth/Loggers/Log4NetLogger.cs
-rw-r--r-- | src/DotNetOAuth/Logger.cs | 36 | ||||
-rw-r--r-- | src/DotNetOAuth/Loggers/Log4NetLogger.cs | 8 | ||||
-rw-r--r-- | src/DotNetOAuth/Loggers/TraceLogger.cs | 10 |
3 files changed, 43 insertions, 11 deletions
diff --git a/src/DotNetOAuth/Logger.cs b/src/DotNetOAuth/Logger.cs index 206efca..96357a0 100644 --- a/src/DotNetOAuth/Logger.cs +++ b/src/DotNetOAuth/Logger.cs @@ -20,9 +20,10 @@ namespace DotNetOAuth { /// </remarks>
internal static class Logger {
/// <summary>
- /// The <see cref="ILog"/> instance that is to be used for the duration of the appdomain.
+ /// The <see cref="ILog"/> instance that is to be used
+ /// by this static Logger for the duration of the appdomain.
/// </summary>
- private static ILog facade = InitializeFacade();
+ private static ILog facade = Create("DotNetOAuth");
#region ILog Members
//// Although this static class doesn't literally implement the ILog interface,
@@ -913,12 +914,39 @@ namespace DotNetOAuth { #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) {
+ if (String.IsNullOrEmpty(name)) {
+ throw new ArgumentNullException("name");
+ }
+
+ return InitializeFacade(name);
+ }
+
+ /// <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) {
+ if (type == null) {
+ throw new ArgumentNullException("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() {
- ILog result = Log4NetLogger.Initialize() ?? TraceLogger.Initialize() ?? NoOpLogger.Initialize();
+ private static ILog InitializeFacade(string name) {
+ ILog result = Log4NetLogger.Initialize(name) ?? TraceLogger.Initialize(name) ?? NoOpLogger.Initialize();
result.Info(Util.LibraryVersion);
return result;
}
diff --git a/src/DotNetOAuth/Loggers/Log4NetLogger.cs b/src/DotNetOAuth/Loggers/Log4NetLogger.cs index 352f8c2..49fd5de 100644 --- a/src/DotNetOAuth/Loggers/Log4NetLogger.cs +++ b/src/DotNetOAuth/Loggers/Log4NetLogger.cs @@ -196,16 +196,16 @@ namespace DotNetOAuth.Loggers { /// Returns a new log4net logger if it exists, or returns null if the assembly cannot be found.
/// </summary>
/// <returns>The created <see cref="ILog"/> instance.</returns>
- internal static ILog Initialize() {
- return IsLog4NetPresent ? CreateLogger() : null;
+ internal static ILog Initialize(string name) {
+ return IsLog4NetPresent ? CreateLogger(name) : null;
}
/// <summary>
/// Creates the log4net.LogManager. Call ONLY after log4net.dll is known to be present.
/// </summary>
/// <returns>The created <see cref="ILog"/> instance.</returns>
- private static ILog CreateLogger() {
- return new Log4NetLogger(log4net.LogManager.GetLogger("DotNetOAuth"));
+ private static ILog CreateLogger(string name) {
+ return new Log4NetLogger(log4net.LogManager.GetLogger(name));
}
}
}
diff --git a/src/DotNetOAuth/Loggers/TraceLogger.cs b/src/DotNetOAuth/Loggers/TraceLogger.cs index 04b0a3c..c55d6df 100644 --- a/src/DotNetOAuth/Loggers/TraceLogger.cs +++ b/src/DotNetOAuth/Loggers/TraceLogger.cs @@ -7,7 +7,11 @@ namespace DotNetOAuth.Loggers { using System.Security.Permissions;
internal class TraceLogger : ILog {
- private TraceSwitch traceSwitch = new TraceSwitch("OpenID", "OpenID Trace Switch");
+ private TraceSwitch traceSwitch;
+
+ internal TraceLogger(string name) {
+ traceSwitch = new TraceSwitch(name, name + " Trace Switch");
+ }
#region ILog Properties
@@ -321,8 +325,8 @@ namespace DotNetOAuth.Loggers { /// if sufficient CAS permissions are granted to use it, otherwise returns false.
/// </summary>
/// <returns>The created <see cref="ILog"/> instance.</returns>
- internal static ILog Initialize() {
- return IsSufficientPermissionGranted ? new TraceLogger() : null;
+ internal static ILog Initialize(string name) {
+ return IsSufficientPermissionGranted ? new TraceLogger(name) : null;
}
}
}
|