写日志

   public static void WriteLogs(string filename, string type, string content)

        {

            string path = AppDomain.CurrentDomain.BaseDirectory;

            if (!string.IsNullOrEmpty(path))

            {

                path = AppDomain.CurrentDomain.BaseDirectory + filename;

                if (!Directory.Exists(path))

                {

                    Directory.CreateDirectory(path);

                }

                path = path + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt";

                if (!File.Exists(path))

                {

                    FileStream fs = File.Create(path);

                    fs.Close();

                }

                if (File.Exists(path))

                {

                    StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default);

                    sw.WriteLine(DateTime.Now.ToString("yyyyMMdd") + type + "-->" + content);

                    sw.Close();

 

                }

 

            }

          

        }

Filename 为 文件夹名称

posted @ 2020-04-12 08:52  红薯红薯  阅读(72)  评论(0)    收藏  举报