• 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
                    { }
                });
  • 相关阅读:
    1491: [NOI2007]社交网络
    Ombrophobic Bovines
    1566: [NOI2009]管道取珠
    1564: [NOI2009]二叉查找树
    1497: [NOI2006]最大获利
    mysql数据库修改字段及新增字段脚本
    NIO
    Lombok用法及标签释义
    idea2017.2延长使用时间
    IDEA 注册码
  • 原文地址:https://www.cnblogs.com/liyangLife/p/4762700.html
Copyright © 2020-2023  润新知