C# 写日志的方法
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();
}
}
}
最新文章
- Docker dockerfile创建Eclipse镜像初试
- win 8 安装 NET framework3.5 方法
- 关于H.264 x264 h264 AVC1
- [py]导入模块3种方法
- nth-child() 选择器
- lintcode:最长上升子序列
- 输出(test)
- Eclipse 各种包说明
- 分别用js和jq实现百度全选反选效果
- LINUX怎么修改IP地址
- 在CentOS/RHEL 6.5上安装Chromium 谷歌浏览器
- WCF 内置跟踪日志
- Python并发式编程
- postman自定义函数实现 时间函数
- JVM内存区域的划分(内存结构或者内存模型)
- 使用My97DatePicker设置日期的属性示例
- Java基础知识_毕向东_Java基础视频教程笔记(13 字符)
- JSON中的{}与[]的区别
- 在sublime3中docblockr插件配置apidoc接口文档注释模板
- 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构
热门文章
- (5.10)mysql高可用系列——percona-toolkit工具下的pt-table-checksum 在线验证主从一致性【续写中】
- (5.3)mysql高可用系列——mysql复制之复制的参数
- const和static const的区别(未整理)
- 基于FCN的图像语义分割
- Two strings CodeForces - 762C (字符串,双指针)
- 解决 mysql (10038)
- Fluent API
- 简单了解journalctl
- 关于获取某月某日最后一天时Calendar的cal.getActualMaximum(Calendar.DAY_OF_MONTH)的吐槽
- Hybrid APP架构设计