SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
ErrorLogger.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using Seci.Definitions;
6 
7 namespace Seci.Helpers
8 {
13  internal static class ErrorLogger
14  {
20  internal static void SeciError(String source, Exception e)
21  {
22  String fileName = setupPaths(false);
23 
24  writeError(source, e.Message, fileName);
25  }
26 
32  internal static void LabViewError(String source, String message)
33  {
34  String fileName = setupPaths(true);
35 
36  writeError(source, message, fileName);
37  }
38 
46  private static String setupPaths(Boolean isLabView)
47  {
48  if (isLabView)
49  {
50  return Status.LabViewErrorDir + "\\" + DateTime.Today.Year + "_" + DateTime.Now.ToString("MMM") + "_" + DateTime.Today.Day + ".txt";
51  }
52 
53  String directory = Status.ErrorDir;
54  String fileName = directory + "\\" + DateTime.Today.Year + "_" + DateTime.Now.ToString("MMM") + "_" + DateTime.Today.Day + ".txt";
55 
56  return fileName;
57  }
58 
66  private static void writeError(String source, String message, String fileName)
67  {
68  try
69  {
70  //Strip out any \n's
71  String error = message;
72  error = error.Replace('\n', ' ');
73 
74  //Create or append file
75  StreamWriter SW = new StreamWriter(fileName, true);
76  SW.WriteLine(DateTime.Now.ToLongTimeString() + " SOURCE: " + source + Environment.NewLine + error + Environment.NewLine);
77  SW.Close();
78  }
79  catch
80  {
81  //Who logs the error when the error logger cannot log?
82  }
83  }
84  }
85 }