zoukankan      html  css  js  c++  java
  • 一个极其简易文本日志类

    namespace MyLogger
    {
        public class NetLog
        {
            private static object lockObj = new object();
            /// <summary>
            /// 写入日志到文本文件
            /// </summary>
            /// <param name="strMessage">日志内容</param>
            public static void WriteTextLog(string strMessage)
            {
                lock(lockObj)
                {
                    string path = AppDomain.CurrentDomain.BaseDirectory + @"Log";
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    DateTime time = DateTime.Now;
                    string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".System.txt";
                    StringBuilder str = new StringBuilder();
    
                    str.Append("Time:" + time + ";Message: " + strMessage + "
    ");
                    StreamWriter sw;
                    if (!File.Exists(fileFullPath))
                    {
                        sw = File.CreateText(fileFullPath);
                    }
                    else
                    {
                        sw = File.AppendText(fileFullPath);
                    }
                    sw.WriteLine(str.ToString());
                    sw.Close();
                }
    
            }
        }
    }
  • 相关阅读:
    css3 object-fit详解
    Timing path
    IUS
    FIFO深度
    UVM中的class--2
    UVM中的class
    Binding
    Concurrent Assertion
    Immediate assertion
    sdf
  • 原文地址:https://www.cnblogs.com/noigel/p/15359210.html
Copyright © 2011-2022 走看看