Created
June 1, 2018 14:43
-
-
Save dpavsrtrl/5ff3c7d2034cce3daf853eb346534b8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.CompilerServices; | |
using NLog; | |
namespace NLogCallerName | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var logger = LogManager.GetLogger("My Log"); | |
logger.LogCaller(LogLevel.Trace, "Gues who"); | |
} | |
} | |
public static class NLogExtensions | |
{ | |
public static void LogCaller(this ILogger logger, LogLevel level, string message, [CallerMemberName] string caller = null) | |
{ | |
var header = caller == null ? "" : $"{caller}: "; | |
logger.Log(level, $"{header}{message}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment