• 自定义Log日志


    新建一个 DataLog类 用来存放生成Log日志方法

    #region 写日志
            public void WriteLogEx(string sendJson, string code = "", string msg = "", string fileName = "")
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string logDir = "log";
                logDir += "\" + DateTime.Now.ToString("yyyy") + "\" + DateTime.Now.ToString("MM");
                path = Path.Combine(path, logDir);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                try
                {
                    StringBuilder log = new StringBuilder();
                    log.Append(Environment.NewLine);
                    log.Append("================BEGIN");
                    log.Append(DateTime.Now);
                    log.Append("================");
                    log.Append(Environment.NewLine);
                    log.Append(sendJson);
                    log.Append(Environment.NewLine);
                    log.Append("调用HTTP请求,返回的数据结果:{"code":" + code + ","msg":" + msg + "}");
                    log.Append(Environment.NewLine);
                    log.Append("================END ");
                    log.Append(DateTime.Now);
                    log.Append("================");
                    log.Append(Environment.NewLine);
    
                    fileName = string.IsNullOrWhiteSpace(fileName) ? DateTime.Now.Day.ToString() + "" : fileName;
                    fileName = fileName + ".txt";
                    string file = Path.Combine(path, fileName);
                    System.IO.File.AppendAllText(file, log.ToString(), System.Text.Encoding.Default);
                }
                catch { }
            }
            #endregion
    View Code

    使用的话直接实例化,调方法。

  • 相关阅读:
    SplitViewController的简单使用
    ViewController容器
    AnchorPoint 和Position 关系
    __OSX_AVAILABLE_BUT_DEPRECATED
    __OSX_AVAILABLE_STARTING
    UIButton重复点击,重复触发,怎么办
    iOS小技巧:用runtime 解决UIButton 重复点击问题
    FOUNDATION_EXPORT 或#define 或 extern
    nginx第一天
    053-001
  • 原文地址:https://www.cnblogs.com/JoeYD/p/12657863.html
Copyright © 2020-2023  润新知