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; }
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(); })); }
} // 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
/// <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)); }
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(); } }
public static string ToMsgTypeString(LogMsgType type) { switch (type) { case LogMsgType.Error: return("E"); case LogMsgType.Warning: return("W"); default: return("I"); } } // func ToMsgTypeString
/// <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); }
/// <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)); }
private void UpdateFilter(bool addFilter, LogMsgType type) { if (addFilter == true) { if (!filter.Contains(type)) { filter.Add(type); } } else { filter.Remove(type); } InitialiseLogQueue(); }
} // 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
private void SetFilter(bool addFilter, LogMsgType type) { if (addFilter == true) { if (!filter.Contains(type)) { filter.Add(type); } } else { filter.Remove(type); } UpdateFilter(); }
} // 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
/// <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(); } } }
} // 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
/// <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); }
/// <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; } }
/// <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(); } )); }
} // 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
} // 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
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); } }
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日志出错"); } }
} // 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
/// <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); }
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); } }
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); }
/// <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; } }
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); }
public static void Log(LogMsgType type, String message) { }
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); } }
/// <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)); }
/************************************************* * ### ####### ####### # ## # ## ## ## ## # # ## ## # ## ## # ## ## # ######## # # ## ## ## # ####### ######## # ####### ####### # ## ## # ## # # ## ## # # ## ## ##### # ## # # ## ####### ###### ######## **************************************************/ /// <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); } } }
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); } }
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(); })); }
/********************************************************** ###### ###### ###### ## ## ## ####### # ## # ## ## ### ## # ## # ###### # # ###### # # # # ## # # # ## ## ## ## # # # # ###### # ## ###### ## ## ## ## # ## ## # # ###### ###### ###### # # ###### # ## ## ## ## # # # # # # # # ### ##### # # ###### # # ## # ## # # # # ##### ###### ####### # # ##### ###### **********************************************************/ /// <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; }
/// <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); })); }
} // 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
public async Task Write(LogMsgType msgtype,string message, string filepath, int linenumber, string methodName, Type type,Exception ex = null) { throw new NotImplementedException(); }
public ILogMessageScope SetType(LogMsgType value, bool force = false) => frame.Scope.SetType(value, force);
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(); }
public void LogMsg(LogMsgType typ, string message) => Console.WriteLine($"[{typ}] {message}");
protected void LogProc(LogMsgType msgType, string logText) { OnTcPluginEvent( new LogEventArgs(PluginNumber, (int)msgType, logText)); }
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
/// <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(); })); }
/// <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; } }