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
                    { }
                });
  • 相关阅读:
    Atitit. 衡量项目规模 包含的类的数量 .net java类库包含多少类 多少个api方法??
    Drawable 中getIntrinsicWidth
    js播放音乐
    Parcelable和Parcel
    标题栏和状态栏
    android振动效果的实现
    Android位置服务和Google地图API初解
    TranslateAnimation详解
    android真机调试
    常见的Android图标大小
  • 原文地址:https://www.cnblogs.com/liyangLife/p/4762700.html
Copyright © 2011-2022 走看看