C#实现的简单实用日志
2009-07-26 12:19
603 查看
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace LogServcie
{
public static class Log
{
public static string LOGMSGPATH ="LogMsg";
public static string ERRMSGPATH = "ErrMsg";
/// <summary>
/// 用于记录用户的操作流程并记录下操作时间
/// </summary>
/// <param name="Logmsg"></param>
public static void writeLog(string Logmsg)
{
string path = System.Environment.CurrentDirectory + "//" + LOGMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//log" + DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the logfile.
sw.WriteLine(Logmsg+" "+DateTime.Now);
}
}
/// <summary>
/// 记录系统运行过程中出现的错误
/// </summary>
/// <param name="Errmsg"></param>
/// <param name="e"></param>
public static void WirteErr(string Errmsg,Exception e)
{
string path = System.Environment.CurrentDirectory + "//" + ERRMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//err"+ DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the errfile.
sw.WriteLine(Errmsg);
sw.WriteLine("出错原因: "+e.Message);
sw.Close();
}
}
/// <summary>
/// 创建制定的文档路径
/// </summary>
/// <param name="path"></param>
private static void CreaterPath(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
if (!dirInfo.Exists)
{
dirInfo.Create();
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace LogServcie
{
public static class Log
{
public static string LOGMSGPATH ="LogMsg";
public static string ERRMSGPATH = "ErrMsg";
/// <summary>
/// 用于记录用户的操作流程并记录下操作时间
/// </summary>
/// <param name="Logmsg"></param>
public static void writeLog(string Logmsg)
{
string path = System.Environment.CurrentDirectory + "//" + LOGMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//log" + DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the logfile.
sw.WriteLine(Logmsg+" "+DateTime.Now);
}
}
/// <summary>
/// 记录系统运行过程中出现的错误
/// </summary>
/// <param name="Errmsg"></param>
/// <param name="e"></param>
public static void WirteErr(string Errmsg,Exception e)
{
string path = System.Environment.CurrentDirectory + "//" + ERRMSGPATH;
CreaterPath(path);
using (StreamWriter sw = new StreamWriter(path + "//err"+ DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default))
{
// Add some text to the errfile.
sw.WriteLine(Errmsg);
sw.WriteLine("出错原因: "+e.Message);
sw.Close();
}
}
/// <summary>
/// 创建制定的文档路径
/// </summary>
/// <param name="path"></param>
private static void CreaterPath(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
if (!dirInfo.Exists)
{
dirInfo.Create();
}
}
}
}
相关文章推荐
- C#实现一个简单实用的TXT文本操作及日志框架详解
- 一个简单实用的C#日志类(第一版)
- c#3.5关于JSON简单操作的实用帮助类(泛型实现)
- 一个简单实用的C#日志类(第二版)
- 基于C#中的Trace实现一个简单的日志系统
- c#3.5关于JSON简单操作的实用帮助类(泛型实现)
- 一个简单实用的C#日志类
- 可替代log4j日志的c#简单日志类队列实现类代码分享
- 简单实用log4j实现日志打印到控制台
- C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志
- 一个简单实用的C#日志类
- 用C#实现的Ping模块,简单实用
- C# GDI绘图—简单画板的实现
- 从头认识Spring-3.2 简单的AOP日志实现-需要记录方法的运行时间
- 从头认识Spring-3.3 简单的AOP日志实现-增加检查订单功能
- 一个简单实用的内存池实现之二 (C实现)
- 从Apache的日志文件收集和提供统计数据(一个Python插件架构的简单实现)
- C#实现桌面应用程序简单的计算器
- C#中使用Socket实现简单Web服务器
- javaCV开发详解之技术杂烩:javaCV能帮我们做什么?能实现什么功能?ffmpeg和openCV能实现功能,javaCV如何做到更快、更简单的实现相应的功能?等等一堆实用话题