• 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;
                }
            }
        }
    }
  • 相关阅读:
    Window 窗口类
    使用 Bolt 实现 GridView 表格控件
    lua的table库
    Windows编程总结之 DLL
    lua 打印 table 拷贝table
    使用 xlue 实现简单 listbox 控件
    使用 xlue 实现 tips
    extern “C”
    COleVariant如何转换为int double string cstring
    原来WIN32 API也有GetOpenFileName函数
  • 原文地址:https://www.cnblogs.com/YuanDong1314/p/13031913.html
Copyright © 2020-2023  润新知