로그 파일 만들기

1108 단어 서류
                string date = DateTime.Now.ToString("yyyy-MM-dd");

                string rootPath = System.Environment.CurrentDirectory;

                //string folderPath = rootPath + @"\Logs";

                string folderPath = @"D:\\Logs";

                string logPath = folderPath + "\\" + date + @".txt";

                if (!Directory.Exists(folderPath))

                {

                    Directory.CreateDirectory(folderPath);

                }

                if (!File.Exists(logPath))

                {

                    File.Create(logPath);

                }

                FileStream fileStream = new FileStream(logPath, FileMode.Append);

                StreamWriter writer = new StreamWriter(fileStream);

                string currentTime = DateTime.Now.ToString();

                writer.WriteLine("【" + currentTime + "】:" + str);

                writer.Dispose();

                writer.Close();

                fileStream.Dispose();

                fileStream.Close();


좋은 웹페이지 즐겨찾기