Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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