zoukankan      html  css  js  c++  java
  • LogHelper 日志和错误日志

    1、这个是记录错误信息的

    /// <summary>
            /// 这个是记录错误信息的
            /// </summary>
            /// <param name="ex"></param>
            /// <param name="Method"></param>
            public static void Error(Exception ex, string Method)
            {
                try
                {
                    string msg = "Call " + Method + " Err:" + DateTime.Now.ToShortTimeString() + "	" + ex.Message;
                    if (ex.InnerException != null) msg += "InnerException:" + ex.InnerException.Message;
                    System.IO.File.AppendAllText(GetFilePath(true), msg + "
    ");
                }
                catch (Exception)
                {
    
                    //throw;
                }
    
            }


    2、这个是作为简单的日志

    /// <summary>
            /// 这个是作为简单的日志
            /// </summary>
            /// <param name="Log"></param>
            public static void Log(string Log)
            {
                try
                {
                    System.IO.File.AppendAllText(GetFilePath(false), "Log:" + DateTime.Now.ToShortTimeString() + "	" + Log + "
    ");
                }
                catch (Exception)
                {
    
                    //throw;
                }
    
    
            }
            private static string GetFilePath(bool isError)
            {
                string path = GetLogPath();
                if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);
                if (isError)
                {
                    path += "\" + DateTime.Today.ToString("yyyyMMdd") + ".err.txt";
                }
                else
                {
                    path += "\" + DateTime.Today.ToString("yyyyMMdd") + ".log.txt";
                }
                return path;
            }
    
            private static string GetLogPath()
            {
                string LogPath = System.Configuration.ConfigurationManager.AppSettings["logPath"] + "";
                if (string.IsNullOrEmpty(LogPath)) LogPath = HttpContext.Current.Server.MapPath("~") + "\log";
                if (!System.IO.Directory.Exists(LogPath)) System.IO.Directory.CreateDirectory(LogPath);
                return LogPath;
            }
        }
    }

    LogHelper.Log("传进来的参数:" + "姓名" + StaffName + "工号" + Dept + "部门" + StaffNo);
                
    LogHelper.Log("URL:" + svcdbWCt.Url);
                 
    LogHelper.Log("返回的Json参数:" + lstInternalStaffNoTel);

  • 相关阅读:
    关于C++中类的static和const成员
    你搞图论有毛用啊!!
    getopt()
    算法设计与分析求最大子段和问题(蛮力法、分治法、动态规划法) C++实现
    CF183 div2 解题报告
    程序员面试中什么最重要?
    php函数基础(一)
    可变参数列表
    ThinkPHP5+小程序商城 网盘视频
    svn里update以后还是有红色的感叹号怎么办
  • 原文地址:https://www.cnblogs.com/iDennis/p/5619699.html
Copyright © 2011-2022 走看看