新浦京81707con > 功能介绍 > WriteLog

原标题:WriteLog

浏览次数:89 时间:2019-05-06

public class WriteLog
    {
        /// <summary>
        /// 成立日志文件
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void CreateLog(Exception ex)
        {
            string path = Application.StartupPath "\log";
            if (!Directory.Exists(path))
            {
                //创造日志文件夹
                Directory.CreateDirectory(path);
            }
            //爆发尤其每一天都创建3个单身的光景文件[*.log],天天的错误消息都在那二个文本里。方便搜索
            path = "\" DateTime.Now.ToShortDateString() ".log";
            WriteLogInfo(ex, path);
        }
        /// <summary>
        /// 写日记音讯
        /// </summary>
        /// <param name="ex">异常类</param>
        /// <param name="path">日志文件存放路线</param>
        private static void WriteLogInfo(Exception ex, string path)
        {
            using (StreamWriter sw = new StreamWriter(path, true, Encoding.Default))
            {
                sw.WriteLine("*****************************************【"
                               DateTime.Now.ToLongTimeString()
                               "】*****************************************");
                if (ex != null)
                {
                    sw.WriteLine("【ErrorType】" ex.GetType());
                    sw.WriteLine("【TargetSite】" ex.TargetSite);
                    sw.WriteLine("【Message】" ex.Message);
                    sw.WriteLine("【Source】" ex.Source);
                    sw.WriteLine("【StackTrace】" ex.StackTrace);
                }
                else
                {
                    sw.WriteLine("Exception is NULL");
                }
                sw.WriteLine();
            }
        }
    }

WriteLog,writelog函数

public class WriteLog
    {
        /// <summary>
        /// 创设日志文件
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void CreateLog(Exception ex)
        {
            string path = Application.StartupPath "\log";
            if (!Directory.Exists(path))
            {
                //创立日志文件夹
                Directory.CreateDirectory(path);
            }
            //发生格外每一日都创制1个独自的生活文件[*.log],天天的错误音讯都在那叁个文书里。方便搜索
            path = "\" DateTime.Now.ToShortDateString() ".log";
            WriteLogInfo(ex, path);
        }
        /// <summary>
        /// 写日记消息
        /// </summary>
        /// <param name="ex">异常类</param>
        /// <param name="path">日志文件存放路线</param>
        private static void WriteLogInfo(Exception ex, string path)
        {
            using (StreamWriter sw = new StreamWriter(path, true, Encoding.Default))
            {
                sw.WriteLine("*****************************************【"
                               DateTime.Now.ToLongTimeString()
                               "】*****************************************");
                if (ex != null)
                {
                    sw.WriteLine("【ErrorType】" ex.GetType());
                    sw.WriteLine("【TargetSite】" ex.TargetSite);
                    sw.WriteLine("【Message】" ex.Message);
                    sw.WriteLine("【Source】" ex.Source);
                    sw.WriteLine("【StackTrace】" ex.StackTrace);
                }
                else
                {
                    sw.WriteLine("Exception is NULL");
                }
                sw.WriteLine();
            }
        }
    }

public class WriteLog { /// summary /// 创立日志文件 /// /summary /// param name=ex格外类/param public static void CreateLog(Exception ex) { stri...

本文由新浦京81707con发布于功能介绍,转载请注明出处:WriteLog

关键词: 新浦京81707con

上一篇:python中的字母转换,过关心得

下一篇:没有了