Created
July 27, 2017 20:45
-
-
Save DominicFinn/9388573e32d771579c48c927983c1c45 to your computer and use it in GitHub Desktop.
These are useful attributes, especially when logging info messages. Caveat. I haven't looked into how much these cost to call...
This file contains 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; | |
using System.Runtime.CompilerServices; | |
namespace ReflectionInfo | |
{ | |
class Program | |
{ | |
static void LogMessage( | |
string logMessage, | |
[CallerFilePath] string callingFilePath = null, | |
[CallerMemberName] string callingMember = null, | |
[CallerLineNumber] int callingLineNumber = 0 | |
) | |
{ | |
Console.WriteLine($"{logMessage}, " + | |
$"Information {Environment.NewLine} " + | |
$"FilePath: {callingFilePath} \n" + | |
$"Member: {callingMember} \n" + | |
$"Line Number: {callingLineNumber}"); | |
} | |
static void Main(string[] args) | |
{ | |
LogMessage("Log this cool story bro"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment