Example #1
0
        internal static void Init()
        {
            Trace.AutoFlush = true;

            logger = new ZCRMLogger();

            logSwitch = new TraceSwitch("ZCRMLogger", "ZCRMSDK Logger");

            string minLoglevel = ZCRMConfigUtil.GetConfigValue(APIConstants.MIN_LOG_LEVEL);

            if (minLoglevel != null && TraceLevel.Off.Equals(APIConstants.LOGGER_LEVELS[minLoglevel]))
            {
                return;
            }

            if ((minLoglevel == null) || (!APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel)))
            {
                logSwitch.Level = TraceLevel.Info;
            }
            else if (APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel))
            {
                logSwitch.Level = APIConstants.LOGGER_LEVELS[minLoglevel];
            }

            string logFile = ZCRMConfigUtil.GetConfigValue(APIConstants.LOG_FILE_PATH);

            if (string.IsNullOrEmpty(logFile))
            {
                logFile = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + Path.DirectorySeparatorChar + APIConstants.LOG_FILE_NAME;
            }
            else
            {
                logFile += APIConstants.LOG_FILE_NAME;
            }

            defaultTrace = new TextWriterTraceListener(logFile);

            Trace.Listeners.Add(defaultTrace);
        }
Example #2
0
        internal static void Init()
        {
            Trace.AutoFlush = true;
            logger          = new ZCRMLogger();
            logSwitch       = new TraceSwitch("ZCRMLogger", "ZCRMSDK Logger");
            string minLoglevel = ZCRMConfigUtil.GetConfigValue(APIConstants.MIN_LOG_LEVEL);

            if ((minLoglevel == null) || (!APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel)))
            {
                logSwitch.Level = TraceLevel.Info;
            }
            else if (APIConstants.LOGGER_LEVELS.ContainsKey(minLoglevel))
            {
                logSwitch.Level = APIConstants.LOGGER_LEVELS[minLoglevel];
            }
            string logFile = ZCRMConfigUtil.GetConfigValue("logFilePath");

            if (string.IsNullOrEmpty(logFile))
            {
                logFile = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + Path.DirectorySeparatorChar + "LogFile.log";
            }
            else
            {
                logFile += "LogFile.log";
            }
            DefaultTraceListener defaultTrace = new DefaultTraceListener
            {
                LogFileName = logFile
            };

            while (Trace.Listeners.Count > 0)
            {
                Trace.Listeners.RemoveAt(0);
            }
            Trace.Listeners.Add(defaultTrace);
        }