C# 获取调用者信息

  • StackTrace
        public  static void LogWrite(string logInfo,
            [CallerFilePath] string file=null,
            [CallerLineNumber] int  line=0,
            [CallerMemberName] string member=null
            )
        {
            Console.WriteLine(logInfo);
            Console.WriteLine(file);
            Console.WriteLine(line);
            Console.WriteLine(member);

        }

https://www.codeproject.com/Tips/606379/Caller-Info-Attributes-in-Csharp-5-0

posted @ 2020-06-07 18:25  百小僧  阅读(794)  评论(0编辑  收藏  举报