try { // Lỗi runtime~ int a = 10; int b = 0; int c = a / b; } catch (Exception ex) { Console.WriteLine("Opps! Co loi xay ra! Vui long lien he Quan tri he thong (0915659223)!"); Console.WriteLine("Vui long goi file log trong thu muc logs den Nha cung cap de khac phuc su co!"); // Ghi log string logFolderName = "logs/"; if (!Directory.Exists(logFolderName)) { // Kiểm tra thư mục log có tồn tại không? Nếu chưa có thì tạo mới Directory.CreateDirectory(logFolderName); } string logFileName = ""; //2019_11_16_log.txt DateTime now = DateTime.Now; logFileName = String.Format("{0}_{1}_{2}_log.txt", now.Year, now.Month, now.Day); // logs/2019_11_16_log.txt //string fullFileLog = logFolderName + "/" + logFileName; string fullFileLog = Path.Combine(logFolderName, logFileName); using (StreamWriter sw = new StreamWriter(fullFileLog)) { sw.WriteLine(String.Format("Loi xay ra vao luc: {0}", now)); sw.WriteLine(String.Format("Loi cu the: {0}", ex.Message)); } // Tu dong am tham goi file log nay ve Server cua ban~ }
Thực hiện các bước tuần tự theo nội dung Bài học nhé!
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!