zoukankan      html  css  js  c++  java
  • 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);
                }
                //发生异常每天都创建一个单独的日子文件[*.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();
                }
            }
        }

  • 相关阅读:
    思源:秒级体验百亿级数据量监控钻取
    禧云Redis跨机房双向同步实践
    谈谈数据中台技术体系
    RCA:收单设备调用云端接口频繁超时排查总结
    技术上的“深淘滩,低作堰”
    企业私有源代码上传github致入侵之大疆案判决了
    那些年我们一起犯过的错
    异地双活的四个误区
    没有预见性你凭什么晋升
    中国IT史上两大严重事故对我们的警醒及预防措施
  • 原文地址:https://www.cnblogs.com/gssajl/p/6215305.html
Copyright © 2011-2022 走看看