首页 > Windows开发 > 详细

C#通过反射获取上层调用方法信息

时间:2015-08-27 13:04:43      阅读:374      评论:0      收藏:0      [点我收藏+]
            System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(1);
            System.Reflection.MethodBase method = frame.GetMethod();
            string namspace = method.DeclaringType.Namespace;
            string clasName = method.ReflectedType.Name;
            string meth = method.Name;
            string FullName = method.DeclaringType.FullName + "." + meth;
  string path = AppDomain.CurrentDomain.BaseDirectory + "/Log/";
            System.Threading.ThreadPool.QueueUserWorkItem((e) =>
            {
                try
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    path += System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                    if (!File.Exists(path))
                    {
                        using (File.Create(path)) { };
                    }
                    FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine("----------------------------------" + System.DateTime.Now.ToString() + "------------------------------------\r\n\r\n异常信息为:\r\n  " + ex + "\r\n");
                    sw.WriteLine("异常信息");
                    sw.Close();
                    fs.Close();
                }
                catch
                { }
            });

 

C#通过反射获取上层调用方法信息

原文:http://www.cnblogs.com/liyangLife/p/4762700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!