00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using System.IO; 00006 using System.Xml; 00007 00008 namespace system_controller { 00009 public class Logger { 00010 protected string _filePath; 00011 protected string _extension; 00012 private string _dataString; 00013 public string DataString { 00014 get { return _dataString; } 00015 set { _dataString = value; } 00016 } 00017 00018 StreamWriter _sWrite; 00019 00020 public delegate void updateStatusEventHandler(); 00021 public event updateStatusEventHandler updateStatusEvent; 00022 00023 public Logger() { 00024 } 00025 00026 public void closeLogFile() { 00027 _sWrite.Flush(); 00028 _sWrite.Close(); 00029 } 00030 00031 public void openFile() { 00032 string dt = DateTime.Now.ToString().Replace('/', '-'); 00033 dt = dt.Replace(':', '-'); 00034 _sWrite = new StreamWriter(_filePath 00035 + dt + _extension); 00036 } 00037 00038 public void write(string data) { 00039 if (updateStatusEvent != null) { 00040 _dataString = data; 00041 updateStatusEvent.Invoke(); 00042 } 00043 try { 00044 _sWrite.Write(data); 00045 _sWrite.Flush(); 00046 } catch (Exception e) { } 00047 } 00048 00049 } 00050 00051 public class DataLogger : Logger { 00052 public DataLogger() { 00053 _filePath = InitializationParameters 00054 .IniFileParameters["path_data_log"]; 00055 _extension = ".data"; 00056 if (!Directory.Exists(_filePath)) 00057 Directory.CreateDirectory(_filePath); 00058 } 00059 } 00060 00061 public class ErrorLogger : Logger { 00062 public ErrorLogger() { 00063 _filePath = InitializationParameters 00064 .IniFileParameters["path_error_log"]; 00065 _extension = ".error"; 00066 if (!Directory.Exists(_filePath)) 00067 Directory.CreateDirectory(_filePath); 00068 } 00069 } 00070 00071 public class EventLogger : Logger { 00072 public EventLogger() { 00073 _filePath = InitializationParameters 00074 .IniFileParameters["path_event_log"]; 00075 _extension = ".event"; 00076 if (!Directory.Exists(_filePath)) 00077 Directory.CreateDirectory(_filePath); 00078 } 00079 } 00080 }