Esempio n. 1
0
        /// <summary>
        /// Log to Logger
        /// </summary>
        /// <param name="str">the message to log</param>
        /// <param name="exLevel">the logging level</param>
        private static void logToLogger(String str, AcLogLevel exLevel)
        {
            String logDateStr = DateTime.Now.ToString("[yyyy-MM-dd][hh:mm:ss.fff]");

            foreach (String logLine in str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (exLevel == AcLogLevel.Debug)
                {
                    _DebugBuilder.AppendFormat("{0} {1}\r\n", logDateStr, logLine);
                }
                else
                {
                    _LogBuilder.AppendFormat("{0}[{1}] {2}\r\n", logDateStr, Enum.GetName(typeof(AcLogLevel), exLevel), logLine);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Log to file
        /// </summary>
        /// <param name="str"></param>
        /// <param name="exL"></param>
        /// <param name="lType"></param>
        public static void Log(String str, AcLogLevel exL, AcLogType lType)
        {
            switch (lType)
            {
            case AcLogType.File:
                logToFile(str, exL);
                break;

            case AcLogType.Logger:
                logToLogger(str, exL);
                break;

            case AcLogType.FileAndLogger:
                logToFile(str, exL);
                logToLogger(str, exL);
                break;

            default:
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Log to file
        /// </summary>
        /// <param name="str">the message to log</param>
        /// <param name="exLevel">the logging level</param>
        /// <remarks>the debug level messages are written to the debug file</remarks>
        private static void logToFile(String str, AcLogLevel exLevel)
        {
            String        logDateStr     = DateTime.Now.ToString("[yyyy-MM-dd][hh:mm:ss.fff]");
            StringBuilder textBuilder    = new StringBuilder();
            String        outputFilename = String.Empty;

            foreach (String logLine in str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (exLevel == AcLogLevel.Debug)
                {
                    outputFilename = DEBUG_FILE;
                    textBuilder.AppendFormat("{0} {1}\r\n", logDateStr, logLine);
                }
                else
                {
                    outputFilename = LOG_FILE;
                    textBuilder.AppendFormat("{0}[{1}] {2}\r\n", logDateStr, Enum.GetName(typeof(AcLogLevel), exLevel), logLine);
                }
            }
            using (StreamWriter sw = new StreamWriter(outputFilename, true, Encoding.UTF8))
            {
                sw.Write(textBuilder.ToString());
            }
        }