简单日志LogHelper
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的更多相关文章
- 【阿里云产品公测】简单日志服务SLS使用评测 + 教程
[阿里云产品公测]简单日志服务SLS使用评测 + 教程 评测介绍 被测产品: 简单日志服务SLS 评测环境: 阿里云基础ECS x2(1核, 512M, 1M) 操作系统: CentOS 6.5 x6 ...
- Golang简单日志类
实现简单的日志写入文件功能运行环境:golang1.4.2+win7x64golang1.4.2+centos6.5×64 package Helper import ( “fmt” “log” “o ...
- SLF4J 简单日志门面 介绍和使用
参考:http://singleant.iteye.com/blog/934593 http://liuzidong.iteye.com/blog/776072 介绍: 简单日记门面(s ...
- python简单日志处理
简单日志处理 import datetime import re logfile='''58.61.164.141 - - [22/Feb/2010:09:51:46 +0800] "GET ...
- Linux 打印简单日志(一)
简单日志输出: #include<stdio.h> #include<string.h> #include<stdlib.h> void write(char* f ...
- C# 简单日志帮助类LogHelper
调用: LogHelper.Debug(""); LogHelper.Info(""); LogHelper.Error(""); 项目添加 ...
- C# 简单日志文本输出
第一种 直接文件IO流写日志文件 using System.IO; public static void WriteLog(string strLog) { string sFilePath=&qu ...
- spring aop简单日志实例
转载自:http://www.blogjava.net/laoding/articles/242611.html 一直就用spring的IOC,遗憾spring的另一重要组成部分AOP却没用过,所以近 ...
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之十 || AOP面向切面编程浅解析:简单日志记录 + 服务切面缓存
代码已上传Github+Gitee,文末有地址 上回<从壹开始前后端分离[ .NET Core2.0 Api + Vue 2.0 + AOP + 分布式]框架之九 || 依赖注入IoC学习 + ...
随机推荐
- BZOJ 2342 [Shoi2011]双倍回文(manacher+堆+set)
题意 N<=500000 题解 维护一个set可以用堆来解决. #include<iostream> #include<cstring> #include<cstd ...
- 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 ...
- 一:1.2【print&input与变量和运算符】
[路径] 绝对路径:从根目录开始链接的路径 --->cd C:\Windows\Boot\DVD\EFI\en-US 相对路径:不从根目录开始链接的路径 ----> cd Boot\DV ...
- ZOJ 3365 Integer Numbers
Integer Numbers Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- Qt 学习之路问题
Qt5 cannot include the file QMainWindow add "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets&qu ...
- 洛谷 P2209 [USACO13OPEN]燃油经济性Fuel Economy
P2209 [USACO13OPEN]燃油经济性Fuel Economy 题目描述 Farmer John has decided to take a cross-country vacation. ...
- Unix发展史
简述 了解过去,我们才能知其然,更知所以然.总结过去,我们才会知道明天该何去何从.在时间的滚轮中,许许多多的东西就像流星一样一闪而逝,而有些东西却能经受着时间的考验散发着经久的魅力,让人津津乐道.流传 ...
- hdu 2102 A计划 具体题解 (BFS+优先队列)
题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...
- less03 混合
less //基本混合 .font_hn{ color: red; font-family: microsoft yahei, "黑体", Arial, Simsun, " ...
- angularjs 服务供应商
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...