zoukankan      html  css  js  c++  java
  • 日志

     /// <summary>
            /// 记录日志
            /// 以日期为文件名,一天一个文件名,每条记录为一个日志
            /// 格式:时间yyyy-MM-dd HH:mm:ss(24h)+空格+日志主体信息
            ///       如:2010-08-08 10:10:10 访问作业系统失败,请检查作业系统是否正常运作。  
            /// </summary>
            /// <param name="strLogPath">输入:日志文件存放路径</param>
            /// <param name="strMsgInfo">输入:日志信息主体信息</param>
            internal static void WriteLog(string strLogPath, string strMsgInfo)
            {
                try
                {
                    //判断路径是否存在
                    DirectoryInfo dirFolderPath = new DirectoryInfo(strLogPath);
                    if (!dirFolderPath.Exists) dirFolderPath.Create();
    
                    string strTodayDate = DateTime.Now.ToString("yyyy-MM-dd");//当前日期
                    string strFileName = dirFolderPath + @"\" + strTodayDate + ".log";
    
                    FileStream fs = null;
                    if (File.Exists(strFileName))
                        fs = new FileStream(strFileName, FileMode.Append, FileAccess.Write);
                    else
                        fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write);
    
                    strMsgInfo = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strMsgInfo + "\n\r";//加上换行符号
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(strMsgInfo);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    CLog.WriteLog("c:\\Log\\LogWriteError", ex.Message + Environment.NewLine + "原始消息:" + Environment.NewLine + strMsgInfo);
                }
            }
    调用:WriteLog("c:\\log", ex.Message);
  • 相关阅读:
    tp5.1批量删除商品
    tp5.1 无限极分类前台展示
    jquery实现商品sku多属性选择(商品详情页)
    简单的权限管理php
    js的常用场景效果
    jquery 常用选择器基础语法学习
    js 注意事项使用误区
    js (单个的)点击式下拉菜单
    React中setState学习总结
    JavaScript面试核心考点(精华)
  • 原文地址:https://www.cnblogs.com/codeloves/p/3006730.html
Copyright © 2011-2022 走看看