public void Log(eLogType i_LogType, string i_MachineName, string i_IP, string i_ServiceName, string i_Info,string i_Elapsed)
 {
     Object obj = new object();
     lock (obj)
     {
         string time = DateTime.Now.ToString();
         m_DataGridView.Rows.Add(new string[] { DateTime.Now.ToString(), Enum.GetName(typeof(eLogType), i_LogType), i_MachineName, i_IP, i_ServiceName, i_Info, i_Elapsed });
     }
 }
Example #2
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="str"></param>
        /// <param name="type"></param>
        public void Add(string str, eLogType type)
        {
            Monitor.Enter(@lock);
            try
            {
                if (m_config.UseConsole)
                {
                    ConsoleColor old = Console.ForegroundColor;
                    Console.ForegroundColor = m_config.ConsoleColors[(int)type];                   
                    Console.WriteLine([email protected]"[{DateTime.Now.ToString()}] {str}");
                    Console.ForegroundColor = old;
                }
                if (m_config.UseFile)
                {
                    if (!m_config.FilePath.IsExistsPath())
                    {
                        Directory.CreateDirectory(m_config.FilePath);
                    }
                    var name = m_config.FilePath + DateTime.Now.ToString("yyyy-MM-dd");
                    var num = 0;

                    while (FileHelper.GetLength(name + (num == 0 ? "" : $"-{num}") + ".log") > 100*1024*1024)//100k
                    {
                        num++;
                    }
                    name = name+( num == 0 ? "" : $"-{num}") +".log";
                    File.AppendAllText(name, 
[email protected]"[{type.ToString()}] {DateTime.Now.ToString()} 
{str}
");
                }
                if(m_config.UseLogView)
                {
                    var a = this.m_config.LogView;
                    a.Select(a.TextLength, 1);  //WTF!!!!!!!
                    a.SelectionColor = m_config.LogViewColors[(int)type];
                    a.IsNewAdd = true;
                    a.AppendLine([email protected]"[{DateTime.Now.ToString()}] {str}");


                }

            }
            catch (Exception e)
            {
                if (this.m_config.UseMessageBox)
                {
                    WinForm.Notice(e.ToString());
                }                
            }
            finally
            {
                Monitor.Exit(@lock);
            }
        }
Example #3
0
        static public void AddLog(string sContent, eLogType LogType)
        {
            if (string.IsNullOrEmpty(sContent))
                return;

            t_Log mLog = new t_Log();
            mLog.ID = "Log:" + DateTime.Now.Ticks;
            mLog.LogTime = DateTime.Now;
            mLog.sContent = sContent;
            mLog.sType = LogType.ToString();

            bLog.Add(mLog);


        }
 public void Log(eLogType i_LogType, AgentInstance i_AgentInstance, string i_Info,string i_Elapsed)
 {
     string machineName = i_AgentInstance.ComputerName;
     string IP = i_AgentInstance.IP;
     Log(i_LogType, machineName, IP, string.Empty, i_Info, i_Elapsed);
 }
Example #5
0
 /// <summary>
 /// Add
 /// </summary>
 /// <param name="str"></param>
 /// <param name="e"></param>
 /// <param name="type"></param>
 public void Add(string str, Exception e, eLogType type) => Add(str + "\n" + e.ToString(),type);
Example #6
0
 /// <summary>
 /// Main function to be called when logging to database is needed.
 /// </summary>
 /// <param name="sMsg">Message to be logged</param>
 /// <param name="_eltType">Type of log</param>
 public void log(string _sMsg, eLogType _eltType)
 {
     Tuple<string, string, DateTime> tupleTemp;
     switch (_eltType)
     {
         case eLogType.LOG_INFO:
             tupleTemp = new Tuple<string, string, DateTime>("Info", _sMsg, DateTime.Now);
             addItemToQueue(tupleTemp);
             break;
         case eLogType.LOG_ERROR:
             tupleTemp = new Tuple<string, string, DateTime>("Error", _sMsg, DateTime.Now);
             addItemToQueue(tupleTemp);
             break;
         case eLogType.LOG_DEBUG:
             tupleTemp = new Tuple<string, string, DateTime>("Debug", _sMsg, DateTime.Now);
             addItemToQueue(tupleTemp);
             break;
     }
 }