• 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);

  • 相关阅读:
    杭电OJ 输入输出练习汇总
    七月读书笔记
    情报分析报告阅读笔记
    情报研究与分析入门阅读笔记
    旁观者攻击
    域前置技术相关学习
    CC攻击和C2的区别
    DNS投毒学习分析总结
    数字证书2.0版本学习总结
    《在树洞里》-感悟
  • 原文地址:https://www.cnblogs.com/iDennis/p/5619699.html
Copyright © 2020-2023  润新知