Example #1
0
 public static void WriteLog(string strLog)
 {
     try
     {
         string        logFilePath = @"C:\Logs\Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt"; //this gives the formmat in which logs should be displayed.
         FileInfo      logFileInfo = new FileInfo(logFilePath);                                                    // it stores the info of the path.
         DirectoryInfo logDirInfo  = new DirectoryInfo(logFileInfo.DirectoryName);
         if (!logDirInfo.Exists)
         {
             logDirInfo.Create();
         }
         using (FileStream fileStream = new FileStream(logFilePath, FileMode.Append))// it will simply append the message to the file
         {
             using (StreamWriter log = new StreamWriter(fileStream))
             {
                 log.WriteLine(strLog);
             }
         }
     }
     catch (Exception e)
     {
         //save the exception in the form of error in the log fil
         log.Error("Error in Writelog: " + e.Message);
     }
 }
 public static void WriteLog(string strLog)
 {
     try
     {
         string        logFilePath = @"C:\Logs\Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
         FileInfo      logFileInfo = new FileInfo(logFilePath);
         DirectoryInfo logDirInfo  = new DirectoryInfo(logFileInfo.DirectoryName);
         if (!logDirInfo.Exists)
         {
             logDirInfo.Create();
         }
         using (FileStream fileStream = new FileStream(logFilePath, FileMode.Append))
         {
             using (StreamWriter log = new StreamWriter(fileStream))
             {
                 log.WriteLine(strLog);
             }
         }
     }
     catch (Exception e) {
         log.Error(e.Message);
     }
 }