Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created June 27, 2014 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/867c4af4275a79d97683 to your computer and use it in GitHub Desktop.
Save tluyben/867c4af4275a79d97683 to your computer and use it in GitHub Desktop.
C# filename/line number logging
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