示例#1
0
 public LogFlagPipe(LogTypes type, LogFlags flags) : base(o =>
 {
     ProcessPipe <String, String> pipe = new EmptyPipe <String>();
     if (flags.HasFlag(LogFlags.PrefixLoggerType))
     {
         pipe = pipe.Connect(new ProcessPipe <String, String>(s => $"[{type}] {s}"));
     }
     if (flags.HasFlag(LogFlags.PrefixTimeStamp))
     {
         pipe = pipe.Connect(new ProcessPipe <String, String>(s => $"[{DateTime.Now:s}] {s}"));
     }
     if (flags.HasFlag(LogFlags.SuffixNewLine))
     {
         pipe = pipe.Connect(new ProcessPipe <String, String>(s => $"{s}{Environment.NewLine}"));
     }
     return(pipe.Process(o));
 }) { }
示例#2
0
 internal ConsoleColor GetColorFromType(LogFlags flags)
 {
     if (flags.HasFlag(LogFlags.APP))
     {
         return(ConsoleColor.DarkGray);
     }
     if (flags.HasFlag(LogFlags.DEBUG))
     {
         return(ConsoleColor.DarkCyan);
     }
     if (flags.HasFlag(LogFlags.ERROR))
     {
         return(ConsoleColor.Red);
     }
     if (flags.HasFlag(LogFlags.NOTICE))
     {
         return(ConsoleColor.Yellow);
     }
     if (flags.HasFlag(LogFlags.IMPORANT))
     {
         return(ConsoleColor.Magenta);
     }
     if (flags.HasFlag(LogFlags.INFO))
     {
         return(m_DefaultColor);
     }
     return(m_DefaultColor);
 }
示例#3
0
        private void LogAdd(string message, LogFlags flags = LogFlags.None)
        {
            if (fMain.IsInitialized == false)
            {
                return;
            }

            //add time
            if ((chkLogTime.IsChecked.Value == true) && (flags.HasFlag(LogFlags.noTime) == false))
            {
                message = DateTime.Now.ToString("yyyy-MM-dd HH\\:mm\\:ss.fff") + "> " + message;
            }

            //new line
            if (!flags.HasFlag(LogFlags.noReturn))
            {
                message += Environment.NewLine;
            }

            //write to file
            if (!flags.HasFlag(LogFlags.toFile))
            {
                lock (writeLock)
                    try
                    {
                        File.AppendAllText(logFileName, message);
                    }
                    catch (Exception e)
                    {
                        message += "[writeFileError]" + e.Message;
                    }
            }

            txtLog.AppendText(message);
            txtLog.ScrollToEnd();
        }