public void WriteLog(string msg)
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + "Log";
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            string logPath = AppDomain.CurrentDomain.BaseDirectory + "Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
            try
            {
                using (StreamWriter sw = File.AppendText(logPath))
                {
                    sw.WriteLine("消息:" + msg);
                    sw.WriteLine("时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    sw.WriteLine("**************************************************");
                    sw.WriteLine();
                    sw.Flush();
                    sw.Close();
                    sw.Dispose();
                }
            }
            catch (IOException e)
            {
                using (StreamWriter sw = File.AppendText(logPath))
                {
                    sw.WriteLine("异常:" + e.Message);
                    sw.WriteLine("时间:" + DateTime.Now.ToString("yyy-MM-dd HH:mm:ss"));
                    sw.WriteLine("**************************************************");
                    sw.WriteLine();
                    sw.Flush();
                    sw.Close();
                    sw.Dispose();
                }
            }
        }

最新文章

  1. Docker dockerfile创建Eclipse镜像初试
  2. win 8 安装 NET framework3.5 方法
  3. 关于H.264 x264 h264 AVC1
  4. [py]导入模块3种方法
  5. nth-child() 选择器
  6. lintcode:最长上升子序列
  7. 输出(test)
  8. Eclipse 各种包说明
  9. 分别用js和jq实现百度全选反选效果
  10. LINUX怎么修改IP地址
  11. 在CentOS/RHEL 6.5上安装Chromium 谷歌浏览器
  12. WCF 内置跟踪日志
  13. Python并发式编程
  14. postman自定义函数实现 时间函数
  15. JVM内存区域的划分(内存结构或者内存模型)
  16. 使用My97DatePicker设置日期的属性示例
  17. Java基础知识_毕向东_Java基础视频教程笔记(13 字符)
  18. JSON中的{}与[]的区别
  19. 在sublime3中docblockr插件配置apidoc接口文档注释模板
  20. 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构

热门文章

  1. (5.10)mysql高可用系列——percona-toolkit工具下的pt-table-checksum 在线验证主从一致性【续写中】
  2. (5.3)mysql高可用系列——mysql复制之复制的参数
  3. const和static const的区别(未整理)
  4. 基于FCN的图像语义分割
  5. Two strings CodeForces - 762C (字符串,双指针)
  6. 解决 mysql (10038)
  7. Fluent API
  8. 简单了解journalctl
  9. 关于获取某月某日最后一天时Calendar的cal.getActualMaximum(Calendar.DAY_OF_MONTH)的吐槽
  10. Hybrid APP架构设计