123456789101112131415161718192021222324252627282930313233343536373839 |
- using System;
- using System.IO;
- namespace ProductionLineMonitor.Application.Services
- {
- public static class LogerHelper
- {
- public static void RecordLogTxt(string message)
- {
- string strPath;
- DateTime dt = DateTime.Now;
- try
- {
- strPath = Directory.GetCurrentDirectory() + "\\Log";
- if (Directory.Exists(strPath) == false)
- {
- Directory.CreateDirectory(strPath);
- }
- //strPath = strPath + "\\" + dt.ToString("yyyy") + "\\" + dt.ToString("MM");
- strPath = strPath + "\\" + dt.ToString("yyyy");
- if (Directory.Exists(strPath) == false)
- {
- Directory.CreateDirectory(strPath);
- }
- strPath = strPath + "\\" + dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day.ToString() + ".txt";
- StreamWriter FileWriter = new StreamWriter(strPath, true);
- FileWriter.WriteLine("[" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "] " + message);
- FileWriter.Close();
- }
- catch (Exception ex)
- {
- string str = ex.Message.ToString();
- }
- }
- }
- }
|