SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
MessageLogger.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  public static class MessageLogger
14  {
21  public static void WriteMessage(String source, String message)
22  {
23  try
24  {
25  String fileName = setupPaths();
26 
27  //Strip out any \n's
28  String mess = message;
29  mess = mess.Replace('\n', ' ');
30 
31  //Create or append file
32  StreamWriter SW = new StreamWriter(fileName, true);
33  SW.WriteLine(DateTime.Now.ToLongTimeString() + " SOURCE: " + source + Environment.NewLine + mess + Environment.NewLine);
34  SW.Close();
35  }
36  catch (Exception err)
37  {
38  ErrorLogger.SeciError("MessageLogger", err);
39  }
40  }
41 
49  private static String setupPaths()
50  {
51  String directory = Status.ErrorDir;
52 
53  DirectoryInfo di = new DirectoryInfo(directory);
54 
55  //Check directory exists
56  if (di.Exists == false)
57  {
58  //then create it
59  di.Create();
60  }
61 
62  String fileName = directory + "\\" + DateTime.Today.Year + "_" + DateTime.Now.ToString("MMM") + "_" + DateTime.Today.Day + "_log.txt";
63 
64  return fileName;
65  }
66 
67  }
68 }
static String setupPaths()
Method for setting up the logging directory. The log files are stored in a directory structure based ...
This class is used for logging messages to file; typical messages are configuration loaded...
static void WriteMessage(String source, String message)
Method for actually writing the message to the file. If the file does not exist it is created otherwi...