在日志文件中添加一行

 

 ///


        /// Append a line to the log 在日志文件中添加一行
        ///

        /// The message to log
        /// The importance level of the message
        public void AppendString(String pLogMess, LogLevel messLevel)
        {
            // Generate localized date for the log event
            DateTime date = DateTime.Now;
            String logEntry = String.Format("[{0}][{1}] {2}", date.ToString("G", CultureManager.Instance().GetCultureInfo()), messLevel, pLogMess);

            //TMP for debug purpose only
            if (this.printToConsole)
            {
                Console.WriteLine(logEntry);
            }

            // Write to the log if the message level is superior or equal to the log level
            if((int)messLevel >= (int) this.LogLevel)
            {
                using (StreamWriter sw = File.AppendText(this.logFile.FullName))
                {
                    sw.WriteLine(logEntry);
                    sw.Flush();
                }
            }
        }

你可能感兴趣的:(日志,C#)