【C#】写日志方法
来源:互联网 发布:大数据处理过程知乎 编辑:程序博客网 时间:2024/04/29 02:31
c# 写日志的方法,几个参数分别标识日志头显示什么,可赋值为空
public class LogTool { public static void WriteLog(string ClassName, string TagType, string ParameterName, string ParameterValue) { StreamWriter sw = null; try { //string logPath = string.Format("{0}Log\\", AppDomain.CurrentDomain.BaseDirectory); string logPath = string.Format("D:\\SelfLog\\SYS"); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } //以日期作为日志文件名 string LogDate = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString(); string logFile = string.Format("{0}\\_log_{1}.log", logPath, LogDate); sw = new StreamWriter(logFile, true); string LogMessage = DateTime.Now.ToString() + "//" + ClassName + "// : " + TagType + "->" + ParameterName + ":[" + ParameterValue + "]"; sw.WriteLine(LogMessage); sw.Close(); } catch { if (sw != null) { sw.Close();//写日志失败,关闭文件 } } } }
0 0
- 【C#】写日志方法
- [C#]log4net写SQLServer数据库日志的配置方法
- [C#]log4net写SQLServer数据库日志的配置方法
- C写日志文件
- 写日志的方法
- C#写日志 方法
- C#写日志方法
- log4net写日志方法
- C/C++写日志代码
- C语言写 系统日志
- 【C++】添加写日志类
- C语言写日志功能
- Linux C写日志文件
- log4j写日志的方法
- 写日志方法的改进
- 一个写日志的方法
- C++快速写日志方法
- [C#]log4net写SQLServer数据库日志的配置方法-.NET教程,C#语言
- 编程之美--求数组的子数组的最大乘积
- object-C中“(classname *) 类名”与 “classname *类名”有什么区别
- inet_addr函数的实现
- .net中的串口类的实时响应性分析
- js圣诞节倒计时网页
- 【C#】写日志方法
- Android jni开发资料--NDK环境搭建
- Leetcode Merge k Sorted Lists 利用stl heap来实现
- 面试题1:把ASCII码整数字符串转换成对应的整数
- java synchronized详解
- MFC对话框程序只能同时运行一个
- IOS中的响应链
- 从C到Object-C基础
- Linux shell 参数展开