class Program { static void Main(string[] args) { Log("测试"); Console.Read(); } public static void Log(string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { string msgToLog = string.Format("{0} ({1} line {2}): {3}", memberName, filePath, lineNumber, msg); Console.WriteLine(msgToLog); } }