一个简单的C#文件日志组件
2010-08-19 20:46
260 查看
最近工作需要一个简单的文件日志组件,Log4net配置太麻烦,在网上找了点资料然后改进了一下。
主要代码如下:
参考文章: Error Logging using ASP.NET 2.0
文件下载: 下载
主要代码如下:
private static void WriteLog(string message) { try { string rootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; if (!rootPath.EndsWith("\\")) { rootPath += "\\"; } string path = rootPath + "Log\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filePath = path + DateTime.Today.ToString("yyyy-mm-dd") + ".txt"; if (!File.Exists(filePath)) { File.Create(filePath).Close(); } using (StreamWriter w = File.AppendText(filePath)) { w.WriteLine("\r\n"); w.WriteLine("{0} ", DateTime.Now.ToString(CultureInfo.InvariantCulture)); w.WriteLine(message); w.Flush(); w.Close(); } } catch (Exception ex) { } }
参考文章: Error Logging using ASP.NET 2.0
文件下载: 下载
相关文章推荐
- 一个简单的C#获取Session、设置Session类文件
- 一个简单的 C# 异步日志记录器
- 用C#代码生成一个简单的PDF文件
- 一个简单实用的C#日志类
- C# 实现一个Log日志文件 以每2Mb创建一个新的日志
- 关于使用C#编写一个简单的日志类
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- Vue封装一个简单轻量的上传文件组件的示例
- 简单的日志文件操作类 (C#)
- 从Apache的日志文件收集和提供统计数据(一个Python插件架构的简单实现)
- 用C#代码生成一个简单的PDF文件
- 一个简单的QQ隐藏图生成算法 通过jQuery和C#分别实现对.NET Core Web Api的访问以及文件上传
- 一个简单的非递归硬盘文件遍历程序(C#版)
- 一个c#对操作系统文件简单操作的类
- KTDictSeg 一个C#.net做的简单快速准确的开源中文分词组件
- Go/Python/Erlang编程语言对比分析及示例 基于RabbitMQ.Client组件实现RabbitMQ可复用的 ConnectionPool(连接池) 封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil 分享基于MemoryCache(内存缓存)的缓存工具类,C# B/S 、C/S项目均可以使用!
- 一个用C#编写的自动读写配置文件的开源组件--V1.0.2版本
- 用C#代码生成一个简单的PDF文件
- VC-Logger 是一个简单易用的 C++ 程序通用日志组件
- 自行控制loadrunner的socket协议性能测试 (转) 一前言 二任务的提出 三实现方案讨论 四技术要点讲解 如何开始录制一个最简单的收发数据包脚本 写日志文件 一行一行读数据包文件 字