public static class LogHelper
{
//日志存储路径
private static string LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.Configuration.ConfigurationManager.AppSettings["LogPath"]); private static object LogLock = new object();//日志锁 /// <summary>
/// 添加正常信息
/// </summary>
/// <param name="message"></param>
public static void AddInfo(string message)
{
string fileName = DateTime.Now.ToString("yyyyMMdd") + ".txt";//日志名称
string fullName = Path.Combine(LogPath, fileName); lock (LogLock)
{
if (!Directory.Exists(LogPath))//如果目录不存在 创建目录
{
Directory.CreateDirectory(LogPath);
}
using (var stream = File.AppendText(fullName))
{
stream.WriteLine(message);
}
Console.WriteLine(message);
}
} /// <summary>
/// 添加错误信息
/// </summary>
/// <param name="errorMessage"></param>
public static void AddError(string errorMessage)
{
string fileName ="Error_"+ DateTime.Now.ToString("yyyyMMdd") + ".txt";//日志名称
string fullName = Path.Combine(LogPath, fileName); lock (LogLock)
{
if (!Directory.Exists(LogPath))//如果目录不存在 创建目录
{
Directory.CreateDirectory(LogPath);
}
using (var stream = File.AppendText(fullName))
{
stream.WriteLine(errorMessage);
}
Console.WriteLine(errorMessage);
}
}
}

简单日志LogHelper的更多相关文章

  1. 【阿里云产品公测】简单日志服务SLS使用评测 + 教程

    [阿里云产品公测]简单日志服务SLS使用评测 + 教程 评测介绍 被测产品: 简单日志服务SLS 评测环境: 阿里云基础ECS x2(1核, 512M, 1M) 操作系统: CentOS 6.5 x6 ...

  2. Golang简单日志类

    实现简单的日志写入文件功能运行环境:golang1.4.2+win7x64golang1.4.2+centos6.5×64 package Helper import ( “fmt” “log” “o ...

  3. SLF4J 简单日志门面 介绍和使用

    参考:http://singleant.iteye.com/blog/934593        http://liuzidong.iteye.com/blog/776072 介绍: 简单日记门面(s ...

  4. python简单日志处理

    简单日志处理 import datetime import re logfile='''58.61.164.141 - - [22/Feb/2010:09:51:46 +0800] "GET ...

  5. Linux 打印简单日志(一)

    简单日志输出: #include<stdio.h> #include<string.h> #include<stdlib.h> void write(char* f ...

  6. C# 简单日志帮助类LogHelper

    调用: LogHelper.Debug(""); LogHelper.Info(""); LogHelper.Error(""); 项目添加 ...

  7. C# 简单日志文本输出

    第一种  直接文件IO流写日志文件 using System.IO; public static void WriteLog(string strLog) { string sFilePath=&qu ...

  8. spring aop简单日志实例

    转载自:http://www.blogjava.net/laoding/articles/242611.html 一直就用spring的IOC,遗憾spring的另一重要组成部分AOP却没用过,所以近 ...

  9. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十 || AOP面向切面编程浅解析:简单日志记录 + 服务切面缓存

    代码已上传Github+Gitee,文末有地址 上回<从壹开始前后端分离[ .NET Core2.0 Api + Vue 2.0 + AOP + 分布式]框架之九 || 依赖注入IoC学习 + ...

随机推荐

  1. BZOJ 2342 [Shoi2011]双倍回文(manacher+堆+set)

    题意 N<=500000 题解 维护一个set可以用堆来解决. #include<iostream> #include<cstring> #include<cstd ...

  2. centos部署nginx服务

    1.准备安装程序 pcrl-8.43.tar.gz  zlib-1.2.11.tar.gz  openssl-1.0.1j.tar.gznginx-1.9.9.tar.gz 2.将下载的包拷贝到/us ...

  3. 一:1.2【print&input与变量和运算符】

    [路径] 绝对路径:从根目录开始链接的路径  --->cd C:\Windows\Boot\DVD\EFI\en-US 相对路径:不从根目录开始链接的路径 ----> cd Boot\DV ...

  4. ZOJ 3365 Integer Numbers

    Integer Numbers Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  5. Qt 学习之路问题

    Qt5 cannot include the file QMainWindow add "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets&qu ...

  6. 洛谷 P2209 [USACO13OPEN]燃油经济性Fuel Economy

    P2209 [USACO13OPEN]燃油经济性Fuel Economy 题目描述 Farmer John has decided to take a cross-country vacation. ...

  7. Unix发展史

    简述 了解过去,我们才能知其然,更知所以然.总结过去,我们才会知道明天该何去何从.在时间的滚轮中,许许多多的东西就像流星一样一闪而逝,而有些东西却能经受着时间的考验散发着经久的魅力,让人津津乐道.流传 ...

  8. hdu 2102 A计划 具体题解 (BFS+优先队列)

    题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...

  9. less03 混合

    less //基本混合 .font_hn{ color: red; font-family: microsoft yahei, "黑体", Arial, Simsun, " ...

  10. angularjs 服务供应商

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...