class Log
{
private readonly static String DateFormat = "yyyyMMdd";
private readonly static String path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"bin\Log";
static Log()
{
try
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
WriteLog("日志路径:", path);
}
catch { }
}

public static void WriteLog(String errorLevel, String log)
{

Console.WriteLine(log+"\n输出位置:Log");
Console.WriteLine();
try
{
DateTime dateTime = DateTime.Now;
String logFile = path + @"\log" + dateTime.ToString(DateFormat) + ".txt";
FileStream fileStream;
StreamWriter streamWriter;
if (File.Exists(logFile))
{
fileStream = new FileStream(logFile, FileMode.Append, FileAccess.Write);
streamWriter = new StreamWriter(fileStream);
streamWriter.WriteLine(dateTime);//开始写入值
streamWriter.WriteLine("ErrorLevel:" + errorLevel);
streamWriter.WriteLine(log);
streamWriter.WriteLine();
streamWriter.Close();
fileStream.Close();
}
else
{
fileStream = new FileStream(logFile, FileMode.Create, FileAccess.Write);
streamWriter = new StreamWriter(fileStream);
streamWriter.WriteLine(dateTime);//开始写入值
streamWriter.WriteLine("ErrorLevel:" + errorLevel);
streamWriter.WriteLine(log);
streamWriter.WriteLine();
streamWriter.Close();
fileStream.Close();
}
}
catch { }
}

/// <summary>
/// 警告信息
/// </summary>
/// <param name="message"></param>
public static void warn(Exception exception)
{
WriteLog("warn", exception.ToString());
}

/// <summary>
/// 警告信息
/// </summary>
/// <param name="message"></param>
public static void warn(String message)
{
WriteLog("warn", message);
}

public static void error(Exception exception)
{
WriteLog("error", exception.ToString());
}

/// <summary>
/// 一般错误信息
/// </summary>
/// <param name="message"></param>
public static void error(String message)
{
WriteLog("error", message);
}

/// <summary>
/// 致命的错误信息
/// </summary>
/// <param name="exception"></param>
public static void fatal(Exception exception)
{
WriteLog("fatal", exception.ToString());
}

/// <summary>
/// 致命的错误信息
/// </summary>
/// <param name="message"></param>
public static void fatal(String message)
{
WriteLog("fatal", message);
}
}

Log 日志收集的更多相关文章

  1. kubernets轻量 contain log 日志收集技巧

    首先这里要收集的日志是容器的日志,而不是集群状态的日志 要完成的三个点,收集,监控,报警,收集是基础,监控和报警可以基于收集的日志来作,这篇主要实现收集 不想看字的可以直接看代码,一共没几行,尽量用调 ...

  2. 日志收集系统elk

    目录 elk简介 官方帮助 rsyslog rsyslog日志采集介绍与使用 综合实验 案例一: 单机ELK部署 案例二. JAVA环境配置,部署 filebeat+Elasticsearch apa ...

  3. 【转】flume+kafka+zookeeper 日志收集平台的搭建

    from:https://my.oschina.net/jastme/blog/600573 flume+kafka+zookeeper 日志收集平台的搭建 收藏 jastme 发表于 10个月前 阅 ...

  4. 【转】Flume日志收集

    from:http://www.cnblogs.com/oubo/archive/2012/05/25/2517751.html Flume日志收集   一.Flume介绍 Flume是一个分布式.可 ...

  5. ELK+kafka构建日志收集系统

    ELK+kafka构建日志收集系统   原文  http://lx.wxqrcode.com/index.php/post/101.html   背景: 最近线上上了ELK,但是只用了一台Redis在 ...

  6. Auty自动化测试框架第三篇——添加异常处理与日志收集

    [本文出自天外归云的博客园] 本次对框架进行完善,增加了日志收集功能和修饰运行功能,完善后的lib目录如下:

  7. 基于Flume的美团日志收集系统(二)改进和优化

    在<基于Flume的美团日志收集系统(一)架构和设计>中,我们详述了基于Flume的美团日志收集系统的架构设计,以及为什么做这样的设计.在本节中,我们将会讲述在实际部署和使用过程中遇到的问 ...

  8. Flume-NG + HDFS + HIVE 日志收集分析

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. DS4700存储日志收集

      a)DS4700存储日志收集              1)收集all support data 1.1.启动客户端”DS Storage manger 10 client”添加控制器IP”192 ...

随机推荐

  1. [转载]oracle xml操作

    /*=====================生成\修改xml========================= */ --xmlelement多个标签层级 SELECT XMLELEMENT(&qu ...

  2. iText输出中文

    使用iTextAsian.jar中的字体 BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont ...

  3. 1、1通过maven建立spring boot项目(不用联网)

    1.把以前spring boot项目的pom.xml导入进来 2.修改pom.xml  里面项目名改成自己项目名 3.复制配置文件 spring: datasource: url: jdbc:mysq ...

  4. [bzoj4665]小w的喜糖_二项式反演

    小w的喜糖 题目链接:https://lydsy.com/JudgeOnline/problem.php?id=4665 数据范围:略. 题解: 二项式反演裸题. $f_{i,j}$表示,前$i$种钦 ...

  5. Mathtype 问题汇总(3)

    1. 调整行间距 2. 调整字号 在 MathType 中,选择「大小 > 定义」将对话框中「完整」所对应的值改为和文字大小匹配的pt(磅值),这样便可以解决在文字编写的 Word 文档中某一行 ...

  6. 使用redis和thread告警并避免重复告警

    spring cloud使用redis 增加监控,微服务的监控体系特别重要,这里增加了告警(使用thread异步告警),同时不能短时间内不能重复告警(使用redis避免重复) 1.增加依赖       ...

  7. 笔记-5:mysql数据更新

    1.插入数据 1.1 插入完整的数据 # 语法格式: INSERT INTO tb_name(column_list) VALUES(value_list); tb_name:指定要插入数据的表名. ...

  8. go slice切片注意跟数组的区别

    一个 slice 会指向一个序列的值,并且包含了长度信息. []T 是一个元素类型为 T 的 slice. [2]string 这样定义久是字符数组 []string 这样定义就是切片 表面上看切片就 ...

  9. 【BFS】Help the Princess!

    题目描述 The people of a certain kingdom make a revolution against the bad government of the princess. T ...

  10. poj 3617 弱鸡贪心

    比赛的时候扣了一道贪心的题目,不会写,,现在补一补一些基础的贪心. 题意:给定一个字符串s,要求按下列操作生成一个新串t--每次从s串中的最前和最后取一个字符给t,要求生成的t字典序最小. 题解:由于 ...