码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-08-27 13:06:13      阅读:184      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!