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. layer弹出层,结合art-template实现弹出编辑

    模板 <!-- 模板 --> <script id="render-tpl" type="text/html"> <div cla ...

  2. [转帖]超详细的EXPDP、IMPDP规范及常用技巧总结

    超详细的EXPDP.IMPDP规范及常用技巧总结 https://www.toutiao.com/i6727232212850180619/ 原创 波波说运维 2019-08-24 00:06:00 ...

  3. 关于db2中listagg函数开发中的体验

    一.首先解释一下可能会查询的基础问题: 1.1db2 “with ur”是什么意思: 在DB2中,共有四种隔离级:RS,RR,CS,UR.以下对四种隔离级进行一些描述,同时附上个人做试验的结果.隔离级 ...

  4. java源码 -- LinkedHashSet

    问题 (1)LinkedHashSet的底层使用什么存储元素? (2)LinkedHashSet与HashSet有什么不同? (3)LinkedHashSet是有序的吗? (4)LinkedHashS ...

  5. 数据分析之--Mataplotlib入门

    目录 Mataplotlib Seaborn 绘制线性图 图片的标题 点和线的样式 X和Y轴可读的映射 直方图 柱状图 条件性柱状图 饼图 箱图 散步图 3D图 Excel数据导入数据库 Matapl ...

  6. 1187: 零起点学算法94——今年暑假不AC(Java)

    1187:零起点学算法94--今年暑假不AC Time Limit: 1 Sec Memory Limit: 32 MB 64bit IO Format: %lld Description " ...

  7. go 结构的方法2

    你可以对包中的 任意 类型定义任意方法,而不仅仅是针对结构体. 但是,不能对来自其他包的类型或基础类型定义方法. package main import (     "fmt"   ...

  8. BZOJ4516 SDOI2016生成魔咒(后缀自动机)

    本质不同子串数量等于所有点的len-parent树上父亲的len的和.可以直接维护. #include<iostream> #include<cstdio> #include& ...

  9. BZOJ4698 SDOI2008Sandy的卡片(后缀自动机)

    差分后即求多串LCS.先考虑两个串怎么做.对第一个串建SAM,第二个串在上面跑即可,任意时刻走到的节点表示的都是第二个串的当前前缀在第一个串中出现的最长的后缀,具体计算长度时每走一个字符长度+1,跳f ...

  10. (十)Activitivi5之启动流程/完成任务的时候设置流程变量

    一.启动流程的时候设置流程变量 1.1 案例 /** * 启动流程实例 */ @Test public void start() { Student student=new Student(); st ...