示例#1
0
        public static string GetIcon(LogStatus LogStatus)
        {
            if (icon.ContainsKey(LogStatus))
                return icon[LogStatus];

            switch (LogStatus.ToString().ToUpper())
            {
                case "FAIL":
                    return "times-circle-o";
                case "ERROR":
                    return "exclamation-circle";
                case "FATAL":
                    return "exclamation-circle";
                case "PASS":
                    return "check-circle-o";
                case "INFO":
                    return "info-circle";
                case "WARNING":
                    return "warning";
                case "SKIP":
                    return "chevron-circle-right";
                default:
                    return "question";
            }
        }
 private static void LogToFile(string pLog, LogStatus pStatus)
 {
     string LogPath = @"C:\ComCon\Log\Log_" + DateTime.Today.Date + ".txt";
     TextWriter tw = new StreamWriter(LogPath, true);
     tw.Write("[" + pStatus.ToString("G") + "]" + pLog);
     tw.Close();
 }
示例#3
0
        public static string GetIcon(LogStatus LogStatus)
        {
            if (icon.ContainsKey(LogStatus))
            {
                return(icon[LogStatus]);
            }

            switch (LogStatus.ToString().ToUpper())
            {
            case "FAIL":
                return("times-circle-o");

            case "ERROR":
                return("exclamation-circle");

            case "FATAL":
                return("exclamation-circle");

            case "PASS":
                return("check-circle-o");

            case "INFO":
                return("info-circle");

            case "WARNING":
                return("warning");

            case "SKIP":
                return("chevron-circle-right");

            default:
                return("question");
            }
        }
示例#4
0
        public static void Log(LogStatus status, string message, [CallerMemberName] string source = null)
        {
            if (Application.Current == null)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(
                () => Logs.MainLog.Items.Add(new LogItem {
                Status = status.ToString(), Source = source, Message = message
            }));
        }
示例#5
0
文件: Logging.cs 项目: whrlpl/engine
        /// <summary>
        /// Write a message to the console.
        /// </summary>
        /// <param name="str">The string to write.</param>
        /// <param name="status">The severity / type of the message.</param>
        public static void Write(string str, LogStatus status = LogStatus.General)
        {
            string formattedStr = "[" + DateTime.Now.ToString() + "] [" + status.ToString() + "] " + str;

            switch (status)
            {
            case LogStatus.Error:
            {
                StackTrace stackTrace      = new StackTrace();
                string     frameMethodName = "";
                for (int i = 0; i < stackTrace.FrameCount; ++i)
                {
                    frameMethodName += stackTrace.GetFrame(i).GetMethod().Name;
                    if (i != stackTrace.FrameCount - 1)
                    {
                        frameMethodName += " --> ";
                    }
                }
                formattedStr           += "\n\tFrom " + frameMethodName;
                Console.ForegroundColor = ConsoleColor.Red;
            }
            break;

            case LogStatus.Critical:
            {
                StackTrace stackTrace      = new StackTrace();
                string     frameMethodName = "";
                for (int i = 0; i < stackTrace.FrameCount; ++i)
                {
                    frameMethodName += stackTrace.GetFrame(i).GetMethod().Name;
                    if (i != stackTrace.FrameCount - 1)
                    {
                        frameMethodName += " --> ";
                    }
                }
                formattedStr           += "\n\tFrom " + frameMethodName;
                Console.ForegroundColor = ConsoleColor.DarkRed;
                throw new Exception("Critical error - game cannot continue: " + formattedStr);
            }
            break;

            case LogStatus.Warning:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;
            }
            OnWrite?.Invoke(null, new LogEventArgs()
            {
                loggedStr = formattedStr
            });
            Console.WriteLine(formattedStr);

            Console.ForegroundColor = ConsoleColor.Gray;
        }
示例#6
0
        public static string GetIcon(LogStatus LogStatus)
        {
            string result;

            if (Icon.icon.ContainsKey(LogStatus))
            {
                result = Icon.icon[LogStatus];
            }
            else
            {
                string text = LogStatus.ToString().ToUpper();
                switch (text)
                {
                case "FAIL":
                    result = "times-circle-o";
                    return(result);

                case "ERROR":
                    result = "exclamation-circle";
                    return(result);

                case "FATAL":
                    result = "exclamation-circle";
                    return(result);

                case "PASS":
                    result = "check-circle-o";
                    return(result);

                case "INFO":
                    result = "info-circle";
                    return(result);

                case "WARNING":
                    result = "warning";
                    return(result);

                case "SKIP":
                    result = "chevron-circle-right";
                    return(result);
                }
                result = "question";
            }
            return(result);
        }
示例#7
0
        public void Log(string str, LogStatus status = LogStatus.General)
        {
            switch (status)
            {
            case LogStatus.Error:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case LogStatus.Warning:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case LogStatus.Success:
                Console.ForegroundColor = ConsoleColor.Green;
                break;
            }
            if (verbose)
            {
                Console.WriteLine("[" + status.ToString() + "] " + str);
            }

            Console.ForegroundColor = ConsoleColor.Gray;
        }
示例#8
0
 static private string CreateLogMessage(LogStatus status, string message)
 {
     return($"{DateTime.Now} [{status.ToString()}] {message} {Environment.NewLine}");
 }
 static private string GetFormattedLogStatusString(LogStatus status)
 {
     return($"[{status.ToString()}]");
 }