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();
                }
            }
        }

  • 相关阅读:
    jdbc连接池工具与pg fdw连接的问题
    关于drill http存储插件http 超时的一些说明
    tds-fdw PostgreSQL said: DB-Library error: DB #: 20002, DB Msg: Adaptive Server connection failed, OS #: 0, OS Msg: Success, Level: 9 问题解决.md
    开发自己的jdbc驱动——可选开发工具
    nexus Invalid state: DELETED; allowed: [STARTED] 问题解决
    airline开发类似git cli 的jar 包
    开发自己的jdbc驱动——基本说明
    nessie 安装&&简单试用
    nessie 类似git 管理数据湖
    一些不错的开源大数据虚拟数据sql 查询引擎
  • 原文地址:https://www.cnblogs.com/gssajl/p/6215305.html
Copyright © 2011-2022 走看看