zoukankan      html  css  js  c++  java
  • Log日志类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace Itcase.log
    {
        public class Log
        {
            public static void WriteLog(string Module, string msg)
            {
                string Err_str = "";
                string Err_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
    
                Err_str = Err_Time + " -> [" + Module + "] -> " + msg;
    
                string strDir = Directory.GetCurrentDirectory() + @"LogErrorLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                try
                {
                    FileStream fs = null;
                    if (File.Exists(strDir))
                    {
                        fs = new FileStream(strDir, FileMode.Append, FileAccess.Write);
                    }
                    else
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"Log");
                        fs = new FileStream(strDir, FileMode.Create);
                    }
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(Err_str);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    
            public void WriteLogs(string msg)
            {
                string Err_str = "";
                string Err_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
    
                Err_str = Err_Time + " -> Reason :" + msg;
    
                string strDir = Directory.GetCurrentDirectory() + @"LogErrorLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                try
                {
                    FileStream fs = null;
                    if (File.Exists(strDir))
                    {
                        fs = new FileStream(strDir, FileMode.Append, FileAccess.Write);
                    }
                    else
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"Log");
                        fs = new FileStream(strDir, FileMode.Create);
                    }
                    StreamWriter sw = new StreamWriter(fs);
                    sw.WriteLine(Err_str);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }
  • 相关阅读:
    糗事百科图片爬取
    Linux文件和目录常用命令
    复习
    Win7的快捷键
    开始运行中的快捷键
    TextBox客户端JS赋值 后台获取(转载)
    window.returnValue的用法
    input的readonly属性与TextBox的ReadOnly和Enabled属性区别
    剖析 ADO.NET 批处理更新
    关于C#多线程的WaitHandle
  • 原文地址:https://www.cnblogs.com/YuanDong1314/p/13031913.html
Copyright © 2011-2022 走看看