You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2018/11/22 03:42:41 UTC

[GitHub] hanabi1224 closed pull request #28: Parameterless log manager get logger

hanabi1224 closed pull request #28: Parameterless log manager get logger
URL: https://github.com/apache/logging-log4net/pull/28
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/LogManager.cs b/src/LogManager.cs
index 59f6b533..9063dc52 100644
--- a/src/LogManager.cs
+++ b/src/LogManager.cs
@@ -18,6 +18,7 @@
 #endregion
 
 using System;
+using System.Diagnostics;
 using System.Reflection;
 
 using log4net.Core;
@@ -261,16 +262,30 @@ public static ILog GetLogger(Type type)
 #endif
 		}
 
-		/// <summary>
-		/// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
-		/// </summary>
-		/// <remarks>
-		/// Gets the logger for the fully qualified name of the type specified.
-		/// </remarks>
-		/// <param name="repository">The repository to lookup in.</param>
-		/// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
-		/// <returns>The logger with the name specified.</returns>
-		public static ILog GetLogger(string repository, Type type) 
+        /// <summary>
+        /// Shorthand for <see cref="M:LogManager.GetLogger()"/>.
+        /// </summary>
+        /// <remarks>
+        /// Get the logger for the fully qualified name of the type of the caller.
+        /// LogManager.GetLogger() is equivalent to LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+        /// </remarks>
+        /// <returns>The logger with the name specified.</returns>
+        public static ILog GetLogger()
+        {
+            var callingMethod = new StackTrace().GetFrame(1).GetMethod();
+            return GetLogger(callingMethod.DeclaringType);
+        }
+
+        /// <summary>
+        /// Shorthand for <see cref="M:LogManager.GetLogger(string)"/>.
+        /// </summary>
+        /// <remarks>
+        /// Gets the logger for the fully qualified name of the type specified.
+        /// </remarks>
+        /// <param name="repository">The repository to lookup in.</param>
+        /// <param name="type">The full name of <paramref name="type"/> will be used as the name of the logger to retrieve.</param>
+        /// <returns>The logger with the name specified.</returns>
+        public static ILog GetLogger(string repository, Type type) 
 		{
 			return WrapLogger(LoggerManager.GetLogger(repository, type));
 		}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services