zoukankan      html  css  js  c++  java
  • C#通过反射获取上层调用方法信息

                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() + "------------------------------------ 异常信息为:   " + ex + " ");
                        sw.WriteLine("异常信息");
                        sw.Close();
                        fs.Close();
                    }
                    catch
                    { }
                });
  • 相关阅读:
    Docker安装MySQL&Redis
    使用VirtualBox+Vagrant快速搭建Linux虚拟机环境
    Java集合工具类的一些坑,Arrays.asList()、Collection.toArray()...
    1.docker常用命令
    4. 带有延迟时间的Queue(DelayQueue)
    3. 基于优先级的Queue(PriorityBlockingQueue)
    2. 常见的Queue
    1. 模拟Queue
    14. 线程调度
    13. 线程池
  • 原文地址:https://www.cnblogs.com/liyangLife/p/4762700.html
Copyright © 2011-2022 走看看