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. Vue style里面使用@import引入外部css, 作用域是全局的解决方案

    问题描述 使用@import引入外部css,作用域却是全局的 <template> </template> <script> export default { na ...

  2. 【codeforces 411B】Multi-core Processor

    [题目链接]:http://codeforces.com/problemset/problem/411/B [题意] 处理器有n个核;然后有k个存储单元; 有m轮工作;每轮工作都会给每个核确定一个数字 ...

  3. 实现图像剪裁 jquery.Jcrop

       配合 jquery.Jcrop 实现上传图片进行剪裁保存功能    <script src="js/jquery.min.js"></script> ...

  4. JS在页面限制checkbox最大复选数

    应该是挺简单的代码, 记录一下分享. 首先最直接的想法就是使用循环, 用局部变量记录已选的checkbox, 达到最大值就将余下的checkbox都禁止选择, 例如以下: <!DOCTYPE h ...

  5. Yocto tips (15): Yocto中的包管理器

    使用包管理器 在local.conf中使能就可以: 然后编译后就会有rpm包了: 配置文件server 能够使用ngix和apache.可是我们也能够仅仅用使用python: python -m Si ...

  6. [Python]Use Flask-Admin with PostgreSQL

    This code recipe gives you an idea of how to use Flask-Admin with postgresql database. from flask im ...

  7. vb.net版机房收费系统——教你七层架构(三)—外观模式

    上次我们看到了D层是如何运作的,如今.我简单演示一下我的外观和B层是如何和U层和D层打交道的. 首先我跟大家说的是我的外观是依照界面功能划分的,粒度有点小,大家在做的时候,记得外观有几个即可了,可是不 ...

  8. Hadoop - YARN NodeManager 剖析

    一 概述         NodeManager是执行在单个节点上的代理,它管理Hadoop集群中单个计算节点,功能包含与ResourceManager保持通信,管理Container的生命周期.监控 ...

  9. What is the difference between SET and SELECT when assigning values to variables, in T-SQL?

    http://vyaskn.tripod.com/differences_between_set_and_select.htm https://stackoverflow.com/questions/ ...

  10. 安卓操作sqlite3,增删改查

    创建 layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...