Ejemplo n.º 1
0
        public bool Add_tab3_log(String text, LogMsgType type, DateTime time)
        {
            string log_mes;
            log_mes = text;
            switch (type)
            {
                case LogMsgType.Error:
                    log_mes = text;
                    break;
                case LogMsgType.Incoming:
                    log_mes = FormatData(text, DataType.Receive, time, TabNum.Tab3, Tab3_wait_receive);
                    Tab3_wait_receive = false;
                    break;
                case LogMsgType.Normal:
                    log_mes = text;
                    break;
                case LogMsgType.Outgoing:
                    log_mes = FormatData(text, DataType.Send, time, TabNum.Tab3, Tab3_wait_receive);
                    Tab3_wait_receive = true;
                    break;
                case LogMsgType.Warning:
                    log_mes = text;
                    break;
                default:
                    break;
            }

            Add_logs(log_mes, type, TabNum.Tab3);
            return true;
        }
Ejemplo n.º 2
0
 private void ShowMsg(LogMsgType msgtype, string msg)
 {
     this.rtb_log.Invoke(new EventHandler(delegate
     {
         rtb_log.TabStop        = false;
         rtb_log.SelectedText   = string.Empty;
         rtb_log.SelectionFont  = new Font(rtb_log.SelectionFont, FontStyle.Bold);
         rtb_log.SelectionColor = LogMsgTypeColor[(int)msgtype];
         rtb_log.AppendText(msg + "\n");
         rtb_log.ScrollToCaret();
     }));
 }
 /// <summary> Log data to the terminal window. </summary>
 /// <param name="msgtype"> The type of message to be written. </param>
 /// <param name="msg"> The string containing the message to be shown. </param>
 private void Log(LogMsgType msgtype, string msg)
 {
     rtfTerminal.Invoke(new EventHandler(delegate
     {
         rtfTerminal.SelectedText   = string.Empty;
         rtfTerminal.SelectionFont  = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
         rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
         rtfTerminal.AppendText(msg);
         rtfTerminal.AppendText("\n");
         rtfTerminal.ScrollToCaret();
     }));
 }
Ejemplo n.º 4
0
        }         // proc Write

        public LogMessageScopeProxy SetType(LogMsgType typ, bool force = false)
        {
            if (scope != null)
            {
                scope.SetType(typ, force);
                if (typ != LogMsgType.Information)
                {
                    scope.AutoFlush();
                }
            }
            return(this);
        }         // proc SetType
Ejemplo n.º 5
0
 /// <summary>
 /// 写日志
 /// </summary>
 public static void LogError(LogMsgType logMsgType, bool PC2VMC, byte[] data, string errorMsg)
 {
     string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
     string strPC2VMC = PC2VMC ? "PC-->VM" : "VM-->PC";
     string strData = "";
     if (data != null && data.Length > 0)
     {
         strData = string.Join(" ", data.ToList<byte>().ConvertAll<string>(a => a.ToString("X2")));
     }
     MT mt = new MT(data);
     string strSubtype = mt.Subtype == 0x00 ? "  " : mt.Subtype.ToString("X2");
     Log(string.Format("{0} |{1}| {2}[MT:{3},subMT:{4}]:{5} {6}", time, logMsgType.ToString().PadRight(6, ' '), strPC2VMC, mt.Type.ToString("X2"), strSubtype, strData, errorMsg));
 }
Ejemplo n.º 6
0
        public void Write(string source, LogMsgType type, string msg, bool newLine)
        {
            Lock();

            string formattedMsg = Formatter.Format(source, type, msg);

            if (!string.IsNullOrEmpty(formattedMsg) && type == LogMsgType.Debug)
            {
                Debug.WriteLine(formattedMsg);
            }

            Unlock();
        }
 public async Task Write(LogMsgType msgtype,string message, string filepath, int linenumber, string methodName, Type type,Exception ex = null)
 {
     LogMessage msg = new LogMessage
     {
         filepath = filepath,
         linenumber = linenumber,
         message = message,
         methodName = methodName,
         mstype = msgtype,
         type = type.Name
     };
     await SQLiteLogConnection.InsertAsync(msg);
 }
 private void Log(LogMsgType msgtype, string msg)
 {
     try
     {
         txtTerm.Dispatcher.Invoke(new EventHandler(delegate
         {
             txtTerm.AppendText(msg);
         }));
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
 }
Ejemplo n.º 9
0
        public static string ToMsgTypeString(LogMsgType type)
        {
            switch (type)
            {
            case LogMsgType.Error:
                return("E");

            case LogMsgType.Warning:
                return("W");

            default:
                return("I");
            }
        }         // func ToMsgTypeString
Ejemplo n.º 10
0
        /// <summary>
        /// Convert LogMsgType to SolidColorBrush
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is LogMsgType))
            {
                return(null);
            }
            LogMsgType      msgType   = (LogMsgType)value;
            SolidColorBrush typeBrush = null;

            switch (msgType)
            {
            case LogMsgType.Debug:
            case LogMsgType.Notification:
            case LogMsgType.Test:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("ConsoleLightBlue");
                break;

            case LogMsgType.Serial:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("ConsoleBlue");
                break;

            case LogMsgType.Tx:
            case LogMsgType.Error:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("ConsoleRed");
                break;

            case LogMsgType.Exception:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("ConsolePurple");
                break;

            case LogMsgType.Warning:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("WarningYellow");
                break;

            case LogMsgType.Rx:
            case LogMsgType.Result:
                typeBrush = (SolidColorBrush)Application.Current.TryFindResource("ConsoleGreen");
                break;

            case LogMsgType.Measurement:
                typeBrush = Brushes.Lime;
                break;

            default:
                typeBrush = Brushes.White;
                break;
            }
            return(typeBrush);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 写日志
        /// </summary>
        public static void LogError(LogMsgType logMsgType, bool PC2VMC, byte[] data, string errorMsg)
        {
            string time      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            string strPC2VMC = PC2VMC ? "PC-->VM" : "VM-->PC";
            string strData   = "";

            if (data != null && data.Length > 0)
            {
                strData = string.Join(" ", data.ToList <byte>().ConvertAll <string>(a => a.ToString("X2")));
            }
            MT     mt         = new MT(data);
            string strSubtype = mt.Subtype == 0x00 ? "  " : mt.Subtype.ToString("X2");

            Log(string.Format("{0} |{1}| {2}[MT:{3},subMT:{4}]:{5} {6}", time, logMsgType.ToString().PadRight(6, ' '), strPC2VMC, mt.Type.ToString("X2"), strSubtype, strData, errorMsg));
        }
Ejemplo n.º 12
0
 private void UpdateFilter(bool addFilter, LogMsgType type)
 {
     if (addFilter == true)
     {
         if (!filter.Contains(type))
         {
             filter.Add(type);
         }
     }
     else
     {
         filter.Remove(type);
     }
     InitialiseLogQueue();
 }
Ejemplo n.º 13
0
        }         // prop SetLogSize

        #endregion

        #region -- IDELogConfig Members ---------------------------------------------------

        void ILogger.LogMsg(LogMsgType typ, string text)
        {
            Debug.Print("[{0}] {1}", Name, text);

            var logLine = new DELogLine(DateTime.Now, typ, text);

            if (Server.Queue?.IsQueueRunning ?? false)
            {
                Server.Queue.Factory.StartNew(() => logFile?.Add(logLine));
            }
            else             // Background thread is not in service, synchron add
            {
                logFile?.Add(logLine);
            }
        }         // proc ILogger.LogMsg
Ejemplo n.º 14
0
 private void SetFilter(bool addFilter, LogMsgType type)
 {
     if (addFilter == true)
     {
         if (!filter.Contains(type))
         {
             filter.Add(type);
         }
     }
     else
     {
         filter.Remove(type);
     }
     UpdateFilter();
 }
Ejemplo n.º 15
0
        }         // proc ProcessLogLine

        private void ProcessReceiveLine(LogMsgType type, StreamReader sr)
        {
            string line;

            while ((line = sr.ReadLine()) != null)
            {
                try
                {
                    ProcessLogLine(LogMsgType.Information, line);
                }
                catch (Exception e)
                {
                    Log.Except(e);
                }
            }
        }         // proc ProcessReceiveLine
Ejemplo n.º 16
0
        /// <summary> Log data to the terminal window. </summary>
        /// <param name="msgtype"> The type of message to be written. </param>
        /// <param name="msg"> The string containing the message to be shown. </param>
        private void Log(LogMsgType msgtype, string msg)
        {
            rchtxtbx_output.Invoke(new EventHandler(delegate
            {
                if (rchtxtbx_output.Lines.Length > 1000
                    ) //remove 500 lines when over 1000 to make sure we do not slow down.
                {
                    rchtxtbx_output.Select(0,
                                           rchtxtbx_output.GetFirstCharIndexFromLine(rchtxtbx_output.Lines.Length - 500));
                    rchtxtbx_output.SelectedText = "";
                }

                rchtxtbx_output.SelectedText   = string.Empty;
                rchtxtbx_output.SelectionFont  = new Font(rchtxtbx_output.SelectionFont, FontStyle.Bold);
                rchtxtbx_output.SelectionColor = LogMsgTypeColor[(int)msgtype];

                if (chkbx_show_data.Checked)
                {
                    if (chckbx_timestamp.Checked) // Check if we are using timestamp or not.
                    {
                        rchtxtbx_output.AppendText(GetTimestamp(DateTime.Now) + msg);
                    }
                    else
                    {
                        rchtxtbx_output.AppendText(msg);
                    }
                }

                rchtxtbx_output.ScrollToCaret();
            }));

            if (chkbx_log.Checked)
            {
                using (StreamWriter sr = File.AppendText(LogFileName))
                {
                    if (chckbx_timestamp.Checked) // Check if we are using timestamp or not.
                    {
                        sr.WriteLine(GetTimestamp(DateTime.Now) + msg);
                    }
                    else
                    {
                        sr.WriteLine(msg);
                    }
                    sr.Close();
                }
            }
        }
Ejemplo n.º 17
0
            }             // proc WriteType

            private string GetLogLineType(LogMsgType typ)
            {
                switch (typ)
                {
                case LogMsgType.Error:
                    return("E");

                case LogMsgType.Information:
                    return("I");

                case LogMsgType.Warning:
                    return("W");

                default:
                    return("");
                }
            }             // func GetLogLineType
Ejemplo n.º 18
0
        /// <summary> Log data to the terminal window. </summary>
        /// <param name="msgtype"> The type of message to be written. </param>
        /// <param name="msg"> The string containing the message to be shown. </param>
        private void Log(LogMsgType msgtype, string msg)
        {
            ar = rtfTerminal.BeginInvoke(new EventHandler(delegate
            {
                if ((msg.Length + rtfTerminal.Text.Length) > maxTextSize)
                {
                    rtfTerminal.Select(0, rtfTerminal.Text.Length - minTextSize);
                }
                rtfTerminal.SelectedText = string.Empty;
                //rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
                rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
                rtfTerminal.Select(rtfTerminal.Text.Length, 0);
                rtfTerminal.AppendText(msg);
                rtfTerminal.ScrollToCaret();

            }));
            EndInvoke(ar);
        }
Ejemplo n.º 19
0
        /// <summary> Log data to the terminal window. </summary>
        /// <param name="msgtype"> The type of message to be written. </param>
        /// <param name="msg"> The string containing the message to be shown. </param>
        private void Log(LogMsgType msgtype, string msg)
        {
            switch (msgtype)
            {
            default:
            case LogMsgType.Copyright:
                rtbConsole.Invoke(new EventHandler(delegate
                {
                    rtbConsole.SelectedText   = string.Empty;
                    rtbConsole.SelectionFont  = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                    rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                    rtbConsole.AppendText(msg);
                    rtbConsole.ScrollToCaret();
                }));
                break;

            case LogMsgType.Outgoing:
                rtbConsole.Invoke(new EventHandler(delegate
                {
                    rtbConsole.SelectedText   = string.Empty;
                    rtbConsole.SelectionFont  = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                    rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                    rtbConsole.AppendText(DateTime.Now.ToLongTimeString());
                    rtbConsole.AppendText(" Tx:");
                    rtbConsole.AppendText(msg);
                    rtbConsole.ScrollToCaret();
                }));
                break;

            case LogMsgType.Incoming:
                rtbConsole.Invoke(new EventHandler(delegate
                {
                    rtbConsole.SelectedText   = string.Empty;
                    rtbConsole.SelectionFont  = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                    rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                    rtbConsole.AppendText(DateTime.Now.ToLongTimeString());
                    rtbConsole.AppendText(" Rx:");
                    rtbConsole.AppendText(msg);
                    rtbConsole.AppendText("\n");
                    rtbConsole.ScrollToCaret();
                }));
                break;
            }
        }
Ejemplo n.º 20
0
 /// <summary> Log data to the terminal window. </summary>
 /// <param name="msgtype"> The type of message to be written. </param>
 /// <param name="msg"> The string containing the message to be shown. </param>
 private void Log(LogMsgType msgtype, string msg)
 {
     rtfTerminal.Invoke(new EventHandler(delegate
     {
         rtfTerminal.SelectedText   = string.Empty;
         rtfTerminal.SelectionFont  = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
         rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
         //rtfTerminal.Focus();
         //rtfTerminal.SelectionStart += rtfTerminal.SelectionStart + 1;
         //rtfTerminal.SelectionLength = 10;
         if (rtfTerminal.Lines.Length > 1000)
         {
             rtfTerminal.Clear();
         }
         rtfTerminal.AppendText(msg + "\r\n");
         rtfTerminal.ScrollToCaret();
     }
                                         ));
 }
Ejemplo n.º 21
0
        }         // func ILogger2.CreateScope

        ILogMessageScope ILogger2.GetScope(LogMsgType typ, bool autoFlush)
        {
            lock (scopes)
            {
                if (scopes.Count == 0)
                {
                    return(((ILogger2)this).CreateScope(typ, autoFlush));
                }
                else
                {
                    var frame = scopes.Last();
                    frame.Scope.SetType(typ);
                    if (autoFlush)
                    {
                        frame.Scope.AutoFlush();
                    }
                    return(new LogMessageScopeHolder(this, frame));
                }
            }
        }         // func ILogger2.GetScope
Ejemplo n.º 22
0
        }         // prop SetLogSize

        #endregion

        #region -- IDELogConfig Members -----------------------------------------------

        void ILogger.LogMsg(LogMsgType type, string text)
        {
            Debug.Print("[{0}] {1}", Name, text);

            // create log line
            if (IsDebug || type != LogMsgType.Debug)
            {
                var logLine = new DELogLine(DateTime.Now, type == LogMsgType.Debug ? LogMsgType.Information : type, text);
                if (Server.Queue?.IsQueueRunning ?? false)
                {
                    Server.Queue.RegisterCommand(() => logFile?.Add(logLine));
                }
                else                 // Background thread is not in service, synchron add
                {
                    logFile?.Add(logLine);
                }
            }

            DEScope.GetScopeService <IDEDebugContext>(false)?.OnMessage(type, text);
        }         // proc ILogger.LogMsg
Ejemplo n.º 23
0
        public static void WriteFileLog(string strLog, LogMsgType logType = LogMsgType.MESSAGE)
        {
            string logFileName = LogFileFullPath;

            if (UseCurrentDataInLogFileName)
            {
                logFileName = $"{Log.LogDir}{DateTime.Now.ToString("yyyyMMdd")}.log";
            }

            if (!Directory.Exists(LogDir))
            {
                Directory.CreateDirectory(LogDir);
            }


            if (logType == LogMsgType.CRITICAL)
            {
                strLog = $"[{DateTime.Now.ToString("HH:mm:ss")}] CRITICAL: {strLog}";
            }

            if (logType == LogMsgType.ERROR)
            {
                strLog = $"[{DateTime.Now.ToString("HH:mm:ss")}] ERROR: {strLog}";
            }

            if (logType == LogMsgType.WARNING)
            {
                strLog = $"[{DateTime.Now.ToString("HH:mm:ss")}] WARNING: {strLog}";
            }

            if (logType == LogMsgType.MESSAGE)
            {
                strLog = $"[{DateTime.Now.ToString("HH:mm:ss")}] MESSAGE: {strLog}";
            }

            if ((int)logType >= Log.MaxLevel)
            {
                Log.WriteTextFile(logFileName, strLog);
            }
        }
Ejemplo n.º 24
0
        public static void log(LogMsgType logtype, string logmsg)
        {
            if (whetherlog == false)
            {
                return;
            }
            try
            {
                DateTime nowTime = DateTime.Now;

                FileStream   fs = new FileStream(logname, FileMode.Append | FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                string type = null;

                if (logtype.Equals(LogMsgType.NSP_LOG_ERR))
                {
                    type = "[error]";
                }
                else if (logtype.Equals(LogMsgType.NSP_LOG_NOTICE))
                {
                    type = "[notice]";
                }
                else
                {
                    type = "[unknown]";
                }

                sw.WriteLine(nowTime.ToString() + " # " + type + " # " + logmsg);

                sw.Flush();
                sw.Close();
                fs.Close();
            }
            catch (Exception) {
                throw new Exception("记录log日志出错");
            }
        }
Ejemplo n.º 25
0
        }         // func GetAcmeUri

        private bool TryGetState(LogMsgType type, out AcmeStateStore state)
        {
            var acmeUri  = GetAcmeUri(Config.GetAttribute("acme", null));
            var hostName = Config.GetAttribute("commonName", null);

            if (acmeUri == null)
            {
                const string msg = "No Automatic Certificate Management Service defined.";
                if (type == LogMsgType.Error)
                {
                    throw new ArgumentNullException(nameof(acmeUri), msg);
                }
                if (type == LogMsgType.Warning)
                {
                    Log.Warn(msg);
                }
                state = null;
                return(false);
            }
            if (hostName == null)
            {
                const string msg = "No HostName defined.";
                if (type == LogMsgType.Error)
                {
                    throw new ArgumentNullException(nameof(acmeUri), msg);
                }
                if (type == LogMsgType.Warning)
                {
                    Log.Warn(msg);
                }
                state = null;
                return(false);
            }

            state = new AcmeStateStore(acmeUri, hostName, Path.ChangeExtension(LogFileName, ".state"));
            return(true);
        }         // func TryGetState
Ejemplo n.º 26
0
        /// <summary>
        /// LogMsg
        /// </summary>
        /// <param name="strType"></param>
        /// <param name="strMsg"></param>
        static public void LogMsg(LogMsgType eType, string strMsg)
        {
            string strType = "";

            switch (eType)
            {
            case LogMsgType.Adding:
                //strType = "Added";
                strType = "Adding";
                break;

            case LogMsgType.Added:
                //strType = "Added";
                strType = "\tAdded";
                break;

            case LogMsgType.Exists:
                //strType = "Exists";
                strType = "\tAlready exists";
                break;

            case LogMsgType.MiscExceptions:
                strType = "Miscelaneous exception";
                // dont log for now
                return;

            case LogMsgType.Info:
                strType = "Info";
                break;

            default:
                strType = "Unknown";
                break;
            }

            m_LogMsgCallback(strType, strMsg);
        }
Ejemplo n.º 27
0
        public static void LogToFile(string strMsg, LogMsgType MsgType)
        {
            StreamWriter file;

            try
            {
                string strFile = ".\\SerialPortLog.log";
                file = new StreamWriter(strFile, true);
                switch (MsgType)
                {
                case LogMsgType.Incoming:
                    file.WriteLine(strMsg);
                    break;

                case LogMsgType.Outgoing:
                    file.WriteLine(strMsg);
                    break;

                case LogMsgType.Normal:
                    file.WriteLine(strMsg);
                    break;

                case LogMsgType.Warning:

                    break;

                case LogMsgType.Error:

                    break;
                }
                file.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 28
0
        public static string TypeToString(LogMsgType type)
        {
            string result = string.Empty;

            switch (type)
            {
            case LogMsgType.Debug:
                result = "Debug";
                break;

            case LogMsgType.Error:
                result = "Error";
                break;

            case LogMsgType.Exception:
                result = "Exception";
                break;

            case LogMsgType.Info:
                result = "Info";
                break;

            case LogMsgType.Warning:
                result = "Warning";
                break;

            case LogMsgType.Timing:
                result = "Timing";
                break;

            case LogMsgType.Workflow:
                result = "Workflow";
                break;
            }

            return(result);
        }
Ejemplo n.º 29
0
 /// <summary> Log data to the terminal window. </summary>
 /// <param name="msgtype"> The type of message to be written. </param>
 /// <param name="msg"> The string containing the message to be shown. </param>
 private void Log(LogMsgType msgtype, string msg)
 {
     switch(msgtype)
     {
         default:
         case LogMsgType.Copyright:
             rtbConsole.Invoke(new EventHandler(delegate
             {
                 rtbConsole.SelectedText = string.Empty;
                 rtbConsole.SelectionFont = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                 rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                 rtbConsole.AppendText(msg);
                 rtbConsole.ScrollToCaret();
             }));
             break;
         case LogMsgType.Outgoing:
             rtbConsole.Invoke(new EventHandler(delegate
             {
                 rtbConsole.SelectedText = string.Empty;
                 rtbConsole.SelectionFont = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                 rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                 rtbConsole.AppendText(DateTime.Now.ToLongTimeString());
                 rtbConsole.AppendText(" Tx:");
                 rtbConsole.AppendText(msg);
                 rtbConsole.ScrollToCaret();
             }));
             break;
         case LogMsgType.Incoming:
             rtbConsole.Invoke(new EventHandler(delegate
             {
                 rtbConsole.SelectedText = string.Empty;
                 rtbConsole.SelectionFont = new Font(rtbConsole.SelectionFont, FontStyle.Bold);
                 rtbConsole.SelectionColor = LogMsgTypeColor[(int)msgtype];
                 rtbConsole.AppendText(DateTime.Now.ToLongTimeString());
                 rtbConsole.AppendText(" Rx:");
                 rtbConsole.AppendText(msg);
                 rtbConsole.AppendText("\n");
                 rtbConsole.ScrollToCaret();
             }));
             break;
     }
 }
Ejemplo n.º 30
0
 public static void Log(LogMsgType type, Exception e)
 {
     // xml creation
     var str = String.Format(@"<error><datetime>{0}</datetime><message>{1}</message><source>{2}</source><stacktrace>{3}</stacktrace></error>", DateTime.UtcNow, e.Message, e.Source, e.StackTrace);
 }
Ejemplo n.º 31
0
 public static void Log(LogMsgType type, String message)
 {
 }
Ejemplo n.º 32
0
 private void Write_log_file(StreamWriter file_ptr, String text, LogMsgType type)
 {
     // Write the alphabet to the file.
     try
     {
         file_ptr.Write(text);
     }
     catch (IOException)
     {
         MessageBox.Show("Can not write file" + file_ptr);
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// 写日志(数据异常)
 /// </summary>
 public static void LogException(LogMsgType logMsgType, bool PC2VMC, string errorMsg, byte[] data)
 {
     string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
     string strPC2VMC = PC2VMC ? "PC-->VM" : "VM-->PC";
     if (data != null && data.Length > 0)
     {
         errorMsg = string.Join(" ", data.ToList<byte>().ConvertAll<string>(a => a.ToString("X2"))) + " " + errorMsg;
     }
     Log(string.Format("{0} |{1}| {2}:{3}", time, logMsgType.ToString().PadRight(6, ' '), strPC2VMC, errorMsg));
 }
Ejemplo n.º 34
0
        /*************************************************
         *      ###     #######   #######
               # ##    #     ##  ##     ##
              ##  #    #      ## ##      #
             ##   ##   #      ## ##      #
             ########  #      #  ##     ##
            ##      #  #######   ########

             #        #######     #######
             #       ##     ##   #      ##
             #       #       ## ##
             #       #       ## ##   #####
             #       ##      #   #      ##
             #######   ######     ########
         **************************************************/
        /// <summary>
        /// Funtion to write data to an object not in current thread
        /// </summary>
        /// <param name="text"></param>
        private void Add_logs(String text, LogMsgType type, TabNum tabNum)
        {
            switch (tabNum)
            {
                case TabNum.Tab1:
                    currentBox = Tab1DataReceive;
                    break;
                case TabNum.Tab2:
                    currentBox = Tab2ReceiveData;
                    break;
                case TabNum.Tab3:
                    currentBox = Tab3_richText;
                    break;
                default:
                    break;
            }

            if (currentBox.InvokeRequired)
            {
                currentBox.BeginInvoke(
                    new MethodInvoker(
                        delegate() { Add_logs(text, type, tabNum); }));
            }
            else
            {
                currentBox.Focus();
                // Set up message
                switch (type)
                {
                    case LogMsgType.Error:
                        currentBox.SelectionColor = Color.Red;
                        break;
                    case LogMsgType.Incoming:
                        currentBox.SelectionColor = Color.Blue;
                        break;
                    case LogMsgType.Normal:
                        currentBox.SelectionColor = Color.Black;
                        break;
                    case LogMsgType.Outgoing:
                        currentBox.SelectionColor = Color.Green;
                        break;
                    case LogMsgType.Warning:
                        currentBox.SelectionColor = Color.Gold;
                        break;
                    case LogMsgType.Coment:
                        currentBox.SelectionColor = Color.DarkOrange;
                        break;
                    default:
                        currentBox.SelectionColor = Color.Black;
                        break;
                }
                currentBox.AppendText(text);

                if (tabNum == TabNum.Tab1)
                {
                    Tab_WriteLog(text);
                }
            }
        }
Ejemplo n.º 35
0
        public static void LogToFile(string strMsg,LogMsgType MsgType)
        {
            StreamWriter file;
              try
              {
              string strFile = ".\\SerialPortLog.log";
              file = new StreamWriter(strFile, true);
              switch (MsgType)
              {
                  case LogMsgType.Incoming:
                      file.WriteLine(strMsg);
                      break;

                  case LogMsgType.Outgoing:
                      file.WriteLine(strMsg);
                      break;

                  case LogMsgType.Normal:
                      file.WriteLine(strMsg);
                      break;

                  case LogMsgType.Warning:

                      break;

                  case LogMsgType.Error:

                      break;
              }
              file.Close();

              }
              catch (Exception e)
              {
              Console.WriteLine(e.Message);
              }
        }
Ejemplo n.º 36
0
 private void Log(LogMsgType msgtype, string msg)
 {
     //Main Thread
     memo.Invoke(new EventHandler(delegate { memo.SelectedText = string.Empty;
     memo.SelectionFont = new Font(memo.SelectionFont, FontStyle.Bold);
     memo.SelectionColor = LogMsgTypeColor[(int)msgtype];
     memo.AppendText(msg + "\n"); //Append text into memo box
     populateTextBox(msg);  //pass string data into another function
     memo.ScrollToCaret(); }));
 }
Ejemplo n.º 37
0
        /**********************************************************
             ######  ######  ######  ##    ##    ##   #######
             #      ##     # ##   ## ###   ##   # ##     #
             ###### #      # ######  # #  # #  ##  #     #
             #      ##    ## ##   ## #  # # #  ######    #
             ##      ######  ##   ## ## ##  # ##    ##   #

            #      ######   ######      ###### #  #     ######
            #     ##    ## ##    ##     #      #  #     #
            #     #      # #   ###      #####  #  #     ######
            #     #     ## #     ##     #      #  #     #
            #####  ######   #######     #      #  ##### ######

         **********************************************************/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file_index"></param>
        /// <param name="logmess"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private bool Tab2_add_log(int file_index, string logmess, LogMsgType type)
        {
            Add_logs(logmess, type, TabNum.Tab2);
            if (FileOut[file_index] != null)
            {
                Write_log_file(FileOut[file_index], logmess, LogMsgType.Outgoing);
            }
            else
            {
                Add_logs("Log file not exist! \n", type, TabNum.Tab2);
                return false;
            }
            return true;
        }
Ejemplo n.º 38
0
        /// <summary> Log data to the terminal window. </summary>
        /// <param name="msgtype"> The type of message to be written. </param>
        /// <param name="msg"> The string containing the message to be shown. </param>
        private void Log(LogMsgType msgtype, string msg)
        {
            rtfTerminal.Invoke(new EventHandler(delegate
              {
              msg = System.DateTime.Now.ToLongTimeString() + ": " + msg;

            switch(msgtype)
            {
            case LogMsgType.Outgoing:
                msg = ">> " + msg;
                break;

            case LogMsgType.Incoming:
                msg = "<< " + msg;
                msg = msg + "\n";
                break;
            default:
                msg = "!! " + msg;
                break;
            }
            rtfTerminal.SelectedText = string.Empty;
            rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
            rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
            rtfTerminal.AppendText(msg);
            rtfTerminal.ScrollToCaret();
            LogToFile(msg,msgtype);
              }));
        }
Ejemplo n.º 39
0
        }         // ctor

        /// <summary>Creates a log line from the given values.</summary>
        /// <param name="stamp"></param>
        /// <param name="typ"></param>
        /// <param name="text"></param>
        public DELogLine(DateTime stamp, LogMsgType typ, string text)
        {
            this.Stamp = stamp;
            this.Typ   = typ;
            this.Text  = text ?? String.Empty;
        }         // ctor
Ejemplo n.º 40
0
 public async Task Write(LogMsgType msgtype,string message, string filepath, int linenumber, string methodName, Type type,Exception ex = null)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 41
0
 public ILogMessageScope SetType(LogMsgType value, bool force = false) => frame.Scope.SetType(value, force);
Ejemplo n.º 42
0
            public void WriteToLog(LogMsgType MsgType, String sText, int iIndentation, String sTag)
            {
                switch (MsgType)
                {
                  case LogMsgType.FatalError:
                  case LogMsgType.Error:
                ++_iErrors;
                _bLastMsgWasError = true;
                _LastMessage = sText;
                break;

                  case LogMsgType.SeriousWarning:
                  case LogMsgType.Warning:
                ++_iWarnings;
                _bLastMsgWasError = false;
                _LastMessage = sText;
                break;

                  case LogMsgType.Success:
                  case LogMsgType.Info:
                  case LogMsgType.Dev:
                  case LogMsgType.Debug:
                ++_iMessages;
                break;
                }

                if (_Parent != null)
                  _Parent.OnLogMsgChanged();
            }
Ejemplo n.º 43
0
 public void LogMsg(LogMsgType typ, string message) => Console.WriteLine($"[{typ}] {message}");
Ejemplo n.º 44
0
 protected void LogProc(LogMsgType msgType, string logText)
 {
     OnTcPluginEvent(
         new LogEventArgs(PluginNumber, (int)msgType, logText));
 }
Ejemplo n.º 45
0
        public static void Parse(string dataLine, out LogMsgType typ, out DateTime stamp, out string text)
        {
            if (String.IsNullOrEmpty(dataLine))
            {
                throw new ArgumentNullException("DataLine");
            }

            var parts = dataLine.Split('\t');

            // Datum Lesen
            stamp = parts.Length > 0 ? ParseDateTime(parts[0]) : DateTime.MinValue;

            // Typ Lesen
            int iTmp;

            if (parts.Length < 2 || !int.TryParse(parts[1], out iTmp) || iTmp < 0 || iTmp > 2)
            {
                typ = LogMsgType.Error;
            }
            else
            {
                typ = (LogMsgType)iTmp;
            }

            // Text Lesen
            if (parts.Length >= 3)
            {
                var sb  = new StringBuilder();
                var tmp = parts[2];
                var pos = 0;
                while (pos < tmp.Length)
                {
                    char c = tmp[pos];
                    switch (c)
                    {
                    case '\\':
                        if (++pos < tmp.Length)
                        {
                            c = tmp[pos++];
                            switch (c)
                            {
                            case 't':
                                sb.Append('\t');
                                break;

                            case 'n':
                                sb.AppendLine();
                                break;

                            case '\\':
                                sb.Append('\\');
                                break;

                            case '0':
                                sb.Append('\0');
                                break;

                            default:
                                sb.Append(c);
                                break;
                            }
                        }
                        break;

                    default:
                        sb.Append(c);
                        pos++;
                        break;
                    }
                }
                text = sb.ToString();
            }
            else
            {
                text = "";
            }
        } // proc Parse
Ejemplo n.º 46
0
 /// <summary>
 /// 写日志(错误日志)
 /// </summary>
 public static void LogError(LogMsgType logMsgType, bool PC2VMC, byte type, byte subtype, string msg)
 {
     string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
     string strPC2VMC = PC2VMC ? "PC-->VM" : "VM-->PC";
     Log(string.Format("{0} |{1}| {2}[MT:{3},subMT:{4}]:{5}", time, logMsgType.ToString().PadRight(6, ' '), strPC2VMC, type.ToString("X2"), subtype.ToString("X2"), msg));
 }
 /// <summary> Log data to the terminal window. </summary>
 /// <param name="msgtype"> The type of message to be written. </param>
 /// <param name="msg"> The string containing the message to be shown. </param>
 private void Log(LogMsgType msgtype, string msg)
 {
     rtfTerminal.Invoke(new EventHandler(delegate
     {
         rtfTerminal.SelectedText = string.Empty;
         rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
         rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
         rtfTerminal.AppendText(msg);
         rtfTerminal.ScrollToCaret();
     }));
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Function Display Prompt Message
 /// </summary>
 /// <param name="text"></param>
 private void Display_prompt(String text, LogMsgType type)
 {
     if (Tab1PromptText.InvokeRequired)
     {
         Tab1PromptText.BeginInvoke(
             new MethodInvoker(
                 delegate() { Display_prompt(text, type); }));
     }
     else
     {
         // Set up message
         switch (type)
         {
             case LogMsgType.Error:
                 Tab1PromptText.ForeColor = Color.Red;
                 break;
             case LogMsgType.Incoming:
                 Tab1PromptText.ForeColor = Color.Blue;
                 break;
             case LogMsgType.Normal:
                 Tab1PromptText.ForeColor = Color.Black;
                 break;
             case LogMsgType.Outgoing:
                 Tab1PromptText.ForeColor = Color.Green;
                 break;
             case LogMsgType.Warning:
                 Tab1PromptText.ForeColor = Color.Peru;
                 break;
             default:
                 Tab1PromptText.ForeColor = Color.Black;
                 break;
         }
         Tab1PromptText.Text = text;
     }
 }