Created
June 27, 2014 08:00
-
-
Save tluyben/867c4af4275a79d97683 to your computer and use it in GitHub Desktop.
C# filename/line number logging
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
public static void Log(string message, params object[] ps) | |
{ | |
message = string.Format (message, ps); | |
var StackTrace = new System.Diagnostics.StackTrace(true); | |
var StackFrame = StackTrace.GetFrame(1); | |
string FileName = StackFrame.GetFileName(); | |
string LineNumber = StackFrame.GetFileLineNumber().ToString(); | |
Console.WriteLine("{0} ({1}): {2}", FileName, LineNumber, message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment