/// <summary> /// FUNCTION - Logger() /// PURPOSE - Initialize private variables /// PARAMTERS - /// RETURN VALUE - /// MODIFIED - 26/10/2012 /// </summary> public Logger(string logfilepath, string filename, int logsize) { // Set Everything to Default values. m_MaxSize = logsize; m_Enabled = false; m_LogFileName = filename;//DefaultLogFileName; m_LoggerFilePath = logfilepath;//DefaultLogFilePath; m_LogLevel = LogPriorityLevel.Functional; OnLogMessage = null; // modified to implement three instance this.SetLogFilePath(m_LoggerFilePath); this.StartLog(m_LogFileName, m_MaxSize, m_LogLevel); }
public LogFilter(LogPriorityLevel level, string tag = ALL) { Level = level; Tag = tag; }
/// <summary> /// FUNCTION - LogMessage /// PURPOSE - Log passed in string into file. /// PARAMTERS - /// RETURN VALUE - /// MODIFIED - 14/05/2007 /// </summary> public void LogMessage(LogPriorityLevel priorityLevel, string format, params object[] varList) { if (m_Enabled == false) { return; } // Check LogLevel if (priorityLevel == LogPriorityLevel.NoLogging || priorityLevel > m_LogLevel) { return; } //try for Format Exceptions string buffer = string.Empty; try { buffer = string.Format(format, varList); } catch { } // Lock this Logger object for Thread Synchronization lock (this) { bool result; result = LogInternal(buffer); } }
/// <summary> /// FUNCTION - StartLog /// PURPOSE - Starts Logging /// PARAMTERS - file name, file size limit and log level /// RETURN VALUE - /// MODIFIED - 26/10/2012 /// </summary> virtual public void StartLog(string fileName, int fileSize, LogPriorityLevel priorityLevel) { m_LogLevel = priorityLevel; m_MaxSize = fileSize * 1000; if (fileName != string.Empty) { m_LogFileName = fileName; } m_Enabled = true; LogMessage(LogPriorityLevel.FatalError, "-----------------------------------------------------------------------------------------------"); LogMessage(LogPriorityLevel.FatalError, "Started Logging with LogLevel: {0} Max FileSize: {1} KBs({2} bytes)", priorityLevel, fileSize, m_MaxSize); }
private bool SetDefaultValues() { // Locals bool bRet = false; try { InitLogger(); Worker.Instance.Logger.LogMessage(LogPriorityLevel.Informational, "Loading default configuration"); _logFolder = DEF_LOG_PATH; _logSize = DEF_LOG_SIZE; _logLevel = DEF_LOG_LEVEL; _appLogFileName = DEF_LOG_NAME; _serviceStatusInterval = DEF_SS_REFRESH; _serviceStatusUrl = DEF_SS_URL; _gtfsRTFInterval = DEF_RTF_REFRESH; _gtfsSFInterval = DEF_SF_REFRESH; _gtfsRTFUrl = DEF_RTF_URL; _gtfsSFUrl = DEF_SF_URL; _gtfsRTFData = DEF_RTF_DATA; _gtfsSFData = DEF_SF_DATA; bRet = true; Worker.Instance.Logger.LogMessage(LogPriorityLevel.Informational, "Successfully intialized with default values."); } catch (Exception ex) { if (null != Worker.Instance.Logger) { Worker.Instance.Logger.LogMessage(LogPriorityLevel.FatalError, "Failed to setup default values. [Error] {0}.", ex.Message); } } return bRet; }
protected override bool UnInitialize() { _logSize = 0; _logLevel = LogPriorityLevel.NoLogging; return base.UnInitialize(); }
/// <summary> /// Loads the configuration from the application directory. /// </summary> /// <returns>true if success.</returns> private bool Load() { // Locals bool bRet = false; XmlDocument xmlDoc = null; string strFile = null; XmlNode xmlNode = null; try { strFile = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(".exe", ".config"); xmlDoc = new XmlDocument(); xmlDoc.Load(strFile); xmlNode = xmlDoc.SelectSingleNode(XPATH_ROOT + NODE_CONF + XPATH_SEP + NODE_LOG); if (null != xmlNode) { if (IsAttrEmpty(xmlNode, ATTR_FOLDER)) { _logFolder = DEF_LOG_PATH; } else { _logFolder = xmlNode.Attributes[ATTR_FOLDER].InnerText; strFile = _logFolder; } bool bLogDirErr = false; if (0 == _logFolder.Length || !Directory.Exists(_logFolder)) { bLogDirErr = true; } if (IsAttrEmpty(xmlNode, ATTR_SIZE)) { _logSize = DEF_LOG_SIZE; } else { _logSize = Convert.ToInt32(xmlNode.Attributes[ATTR_SIZE].InnerText); } if (IsAttrEmpty(xmlNode, ATTR_SIZE)) { _logLevel = DEF_LOG_LEVEL; } else { _logLevel = (LogPriorityLevel)Enum.Parse(typeof(LogPriorityLevel), xmlNode.Attributes[ATTR_LEVEL].InnerText); } if (bLogDirErr) { InitLogger(); Worker.Instance.Logger.LogMessage(LogPriorityLevel.NonFatalError, "Failed to load log folder {0} so now using application folder {1}.", strFile, _logFolder); } } xmlNode = xmlDoc.SelectSingleNode(XPATH_ROOT + NODE_CONF + XPATH_SEP + NODE_PROXY); if (null != xmlNode) { if (!IsAttrEmpty(xmlNode, ATTR_ADDR)) { _proxyAddress = xmlNode.Attributes[ATTR_ADDR].InnerText; } if (!IsAttrEmpty(xmlNode, ATTR_PORT)) { _proxyPort = Convert.ToUInt16(xmlNode.Attributes[ATTR_PORT].InnerText); } } xmlNode = xmlDoc.SelectSingleNode(XPATH_ROOT + NODE_CONF + XPATH_SEP + NODE_GTFS + XPATH_SEP + NODE_SBWY + XPATH_SEP + NODE_STSF); if (null != xmlNode) { if (IsAttrEmpty(xmlNode, ATTR_REFRESH)) { _serviceStatusInterval = DEF_SS_REFRESH; } else { _serviceStatusInterval = Convert.ToUInt16(xmlNode.Attributes[ATTR_REFRESH].InnerText); } if (IsAttrEmpty(xmlNode, ATTR_URL)) { _serviceStatusUrl = DEF_SS_URL; } else { _serviceStatusUrl = xmlNode.Attributes[ATTR_URL].InnerText; } } else { _serviceStatusInterval = DEF_SS_REFRESH; _serviceStatusUrl = DEF_SS_URL; } xmlNode = xmlDoc.SelectSingleNode(XPATH_ROOT + NODE_CONF + XPATH_SEP + NODE_GTFS + XPATH_SEP + NODE_SBWY + XPATH_SEP + NODE_RTF); if (null != xmlNode) { if (IsAttrEmpty(xmlNode, ATTR_REFRESH)) { _gtfsRTFInterval = DEF_RTF_REFRESH; } else { _gtfsRTFInterval = Convert.ToUInt16(xmlNode.Attributes[ATTR_REFRESH].InnerText); } if (IsAttrEmpty(xmlNode, ATTR_URL)) { _gtfsRTFUrl = DEF_RTF_URL; } else { _gtfsRTFUrl = xmlNode.Attributes[ATTR_URL].InnerText; } if (IsAttrEmpty(xmlNode, ATTR_DATA)) { _gtfsRTFData = DEF_RTF_DATA; } else { _gtfsRTFData = xmlNode.Attributes[ATTR_DATA].InnerText; } } else { _gtfsRTFInterval = DEF_RTF_REFRESH; _gtfsRTFUrl = DEF_RTF_URL; _gtfsRTFData = DEF_RTF_DATA; } xmlNode = xmlDoc.SelectSingleNode(XPATH_ROOT + NODE_CONF + XPATH_SEP + NODE_GTFS + XPATH_SEP + NODE_SBWY + XPATH_SEP + NODE_SF); if (null != xmlNode) { if (IsAttrEmpty(xmlNode, ATTR_REFRESH)) { _gtfsSFInterval = DEF_SF_REFRESH; } else { _gtfsSFInterval = Convert.ToUInt16(xmlNode.Attributes[ATTR_REFRESH].InnerText); } if (IsAttrEmpty(xmlNode, ATTR_URL)) { _gtfsSFUrl = DEF_SF_URL; } else { _gtfsSFUrl = xmlNode.Attributes[ATTR_URL].InnerText; } if (IsAttrEmpty(xmlNode, ATTR_DATA)) { _gtfsSFData = DEF_SF_DATA; } else { _gtfsSFData = xmlNode.Attributes[ATTR_DATA].InnerText; } } else { _gtfsSFInterval = DEF_SF_REFRESH; _gtfsSFUrl = DEF_SF_URL; _gtfsSFData = DEF_SF_DATA; } InitLogger(); bRet = true; if (!bRet) { bRet = SetDefaultValues(); } } catch (Exception ex) { InitLogger(); Worker.Instance.Logger.LogMessage(LogPriorityLevel.FatalError, "Failed to load configuration. [Error] {0}.", ex.Message); if (!bRet) { bRet = SetDefaultValues(); } } return bRet; }