Example #1
0
        public static void Apply(LogLevel level, string logText, params object[] context)
        {
            //disable level, we do not apply this log
            if (mLogLevelEnable[(int)level] == false)
            {
                return;
            }

            var logString = "[" + LogLevelConvert.ToString(level) + "] " + StringProperty.Log + logText;

            LogPrint.Print(LogFormat.ApplyLog(logString, context));
        }
Example #2
0
        static LogEmitter()
        {
            LogPrint = new LogPrint((Log log) =>
            {
                //for all element
                foreach (var logElement in log.Elements)
                {
                    //change write color and write, at least reset color
                    Console.ForegroundColor = EnumerationConvert.ToConsoleColor(logElement.Color);
                    Console.Write(logElement.Text);
                    Console.ResetColor();
                }
                Console.WriteLine();
            });

            //init default log format
            LogFormat       = new LogFormat();
            LogFormat.Color = LogColor.Gray;

            //set the log key [time] means current date time (green)
            LogFormat.AddLogKey("time", new LogKey((LogKey logKey) => DateTime.Now.ToString(), true, LogColor.Green));

            //set the log key ["LogLevel"] means log level (with color)
            for (LogLevel logLevel = 0; logLevel < LogLevel.Count; logLevel++)
            {
                //get color and string
                var logLevelColor  = LogLevelConvert.ToColor(logLevel);
                var logLevelString = LogLevelConvert.ToString(logLevel);

                //set string and color to log key
                LogFormat.AddLogKey(logLevelString, new LogKey((LogKey logKey) => logLevelString, true, logLevelColor));
            }

            //create enable array and set it to true
            mLogLevelEnable = new bool[(int)LogLevel.Count];
            for (int i = 0; i < mLogLevelEnable.Length; i++)
            {
                mLogLevelEnable[i] = true;
            }
        }