LogWriter.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. public class LogWriter
  5. {
  6. private string m_exePath = string.Empty;
  7. private string Participant;
  8. public string BodyLocation;
  9. private string Orientation;
  10. public LogWriter(String Participant, String BodyLocation, String Orientation)
  11. {
  12. this.Participant = Participant;
  13. this.BodyLocation = BodyLocation;
  14. this.Orientation = Orientation;
  15. }
  16. public LogWriter(string logMessage)
  17. {
  18. LogWrite(logMessage);
  19. }
  20. public void LogWrite(string logMessage)
  21. {
  22. m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  23. m_exePath += "\\" + Participant;
  24. System.IO.Directory.CreateDirectory(m_exePath);
  25. try
  26. {
  27. using (StreamWriter w = File.AppendText(m_exePath + "\\" + Participant + "_" + BodyLocation + "_" + Orientation +".txt"))
  28. {
  29. Log(logMessage, w);
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. }
  35. }
  36. public void LogWrite(string logMessage, string filename)
  37. {
  38. m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  39. m_exePath += "\\" + Participant;
  40. System.IO.Directory.CreateDirectory(m_exePath);
  41. try
  42. {
  43. using (StreamWriter w = File.AppendText(m_exePath + "\\" + filename + ".txt"))
  44. {
  45. Log(logMessage, w);
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. }
  51. }
  52. public void Log(string logMessage, TextWriter txtWriter)
  53. {
  54. try
  55. {
  56. txtWriter.Write("\r\nLog Entry : ");
  57. txtWriter.WriteLine("{0}", DateTime.Now);
  58. txtWriter.WriteLine(" :{0}", logMessage);
  59. txtWriter.WriteLine("-------------------------------");
  60. }
  61. catch (Exception ex)
  62. {
  63. }
  64. }
  65. }