首页 > 代码库 > C#中简单的写日志的方法

C#中简单的写日志的方法

public static void WriteLog(string msg)
        {
            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            string ServerPath = appPath + @"\Log" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

            StreamWriter srWriter = new StreamWriter(ServerPath, true);
            string WriteStr = "************************************************************************************************\r\n";
            WriteStr += "Date:" + DateTime.Now.ToString() + "  \r\n" + msg;
            srWriter.WriteLine(WriteStr);
            srWriter.Close();
        }