• 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;
                }
            }
        }
    }
  • 相关阅读:
    volatile用法
    static用法
    sizeof用法
    C语言void关键字的深刻含义
    extern用法
    const用法
    attribute用法
    Task的运行过程分析
    Android BroadcastReceiver实例Demo(有序广播的发送)
    旅行-许巍
  • 原文地址:https://www.cnblogs.com/YuanDong1314/p/13031913.html
Copyright © 2020-2023  润新知