简单日志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学习 + ...
随机推荐
- 计数排序(counting-sort)
计数排序是一种稳定的排序算法,它不是比较排序.计数排序是有条件限制的:排序的数必须是n个0到k的数,所以计数排序不适合给字母排序.计数排序时间复杂度:O(n+k),空间复杂度:O(k),当k=n时,时 ...
- 单机Mongo复制集安装配置(数据库版本:4.x)
官方文档: https://docs.mongodb.com/manual/tutorial/deploy-replica-set-with-keyfile-access-control/#dep ...
- 浅谈python 中正则的一些函数
主要的函数有 : match() search() findall() group() groups() split() match (): 含义 开头匹配,匹配成功返回一个对象失败则 ...
- 【hdu 1890】Robotic Sort
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1890 [题意] 给你n个数字; i从1到n; 每次让你把第i小的数和数组的第i个元素之间这段区间内 ...
- 洛谷 P1702 突击考试
P1702 突击考试 题目描述 一日,老师决定进行一次突击考试.已知每个学生都有一个考试能力等级,教室里一共有N个课桌,按照顺序排成一列,每张课桌可以坐两个人,第i张课桌坐的两个人的能力等级为(A[i ...
- 国庆 day 7 上午
思路:模拟,set记录一下. #include<set> #include<cstdio> #include<cstring> #include<iostre ...
- layDate1.0正式公布,您一直在寻找的的js日期控件
你是时候换一款日期控件了,而layDate很愿意和您成为工作伙伴.她正致力于成为全球最高大上的web日期支撑,为国内外全部从事web应用开发的同仁提供力所能及的动力.她基于原生JavaScript精心 ...
- [P3097] [USACO13DEC] [BZOJ4094] 最优挤奶Optimal Milking 解题报告(线段树+DP)
题目链接:https://www.luogu.org/problemnew/show/P3097#sub 题目描述 Farmer John has recently purchased a new b ...
- laravel中的数据迁移和数据填充
laravel中的数据迁移和数据填充 标签(空格分隔): php 生成迁移文件两种方式: 1 新建一个表的迁移文件 php artisan make:migration create_students ...
- 4.C语言文件操作
总论 1.fopen r以只读方式打开文件,该文件必须存在 r+以可读写方式打开文件,文件必须存在 rb+读写打开一个二进制文件,允许读写数据,文件必须存在 rw+读写打开一个文本文件,允许读和写 w ...