コード例 #1
0
        /// <summary>
        /// Format
        /// </summary>
        /// <param name="record">LogRecord</param>
        /// <returns>formatted string</returns>
        public override String Format(LogRecord record)
        {
            StringBuilder sb = new StringBuilder();
            //time of execution
            string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ms");

            time = time + "00";

            /**	Time/Error		*/
            if (record.GetLevel() == Level.SEVERE)
            {
                //         12.12.12.123
                sb.Append("===========> ");
                sb.Append("    (SEVERE)   ");
                //if (VAdvantage.DataBase.Ini.IsClient())
                //    System.Media.SystemSounds.Beep.Play();
            }
            else if (record.GetLevel() == Level.WARNING)
            {
                //         12.12.12.123
                sb.Append("-----------> ");
                sb.Append("    (WARNING)  ");
            }
            else
            {
                //123456789123456789
                sb.Append(time.Substring(11, 23 - 11));
                //int spaces = 11;
                if (record.GetLevel() == Level.INFO)
                {
                    sb.Append("    (INFO)     ");
                }
                else if (record.GetLevel() == Level.CONFIG)
                {
                    sb.Append("    (CONFIG)   ");
                }
                else if (record.GetLevel() == Level.FINE)
                {
                    sb.Append("    (FINE)     ");
                }
                else if (record.GetLevel() == Level.FINER)
                {
                    sb.Append("    (FINER)    ");
                }
                else if (record.GetLevel() == Level.FINEST)
                {
                    sb.Append("    (FINEST)   ");
                }
                //sb.Append("                          ".Substring(0, spaces));
            }

            /**	Class.method	**/
            if (!_shortFormat)
            {
                sb.Append(GetClassMethod(record)).Append(": ");
            }

            /**	Message			**/
            sb.Append(record.message);

            //sb.Append(record.sourceClassName + "." + record.sourceMethodName + " > " + record.lineNumber + " > " + record.message);
            return(sb.ToString());
        }
コード例 #2
0
        public override void Publish(LogRecord record)
        {
            //if (DateTime.Now.Hour != Convert.ToDateTime(_lastFileDate).Hour) //Set Now Date
            //{
            //    Initialize(_viennaHome, true, true);
            //}

            if (DateTime.Now > Convert.ToDateTime(_lastFileDate).AddHours(1)) //Set Now Date
            {
                Initialize(_viennaHome, true, true);
            }

            if (!IsLoggable(record) || _writer == null)
            {
                return;
            }

            //	Format
            String msg = null;

            try
            {
                msg = GetFormatter().Format(record);
            }
            catch
            {
                return;
            }

            try
            {
                if (!_doneHeader)
                {
                    _writer.WriteLine(GetFormatter().GetHead());
                    //AllocConsole();
                    //Console.WriteLine(GetFormatter().GetHead()); // outputs to console window
                    _doneHeader = true;
                }
                _writer.WriteLine(msg);
                //AllocConsole();
                //Console.WriteLine(msg); // outputs to console window
                m_records++;

                //if (string.IsNullOrEmpty(record.message))
                //    record.message = "Executed";
                if (record.GetLevel() == Level.SEVERE ||
                    record.GetLevel() == Level.WARNING ||
                    m_records % 10 == 0)        //	flush every 10 records
                {
                    Flush();
                }
                //print into file
                //_writer.WriteLine(this.Format(record));
                //_writer.Flush();   //finally flush the print
            }
            catch
            {
                Close();
                _lastFileDate = null; //try next time when publish is called
                //try again to initlize file
            }
        }
コード例 #3
0
ファイル: Formatter.cs プロジェクト: vuongthai91/ERP-CMR-DMS
 /// <summary>
 /// Format the record stored in LogRecord
 /// </summary>
 /// <param name="record">LogRecord</param>
 /// <returns>formatted string</returns>
 public abstract String Format(LogRecord record);
コード例 #4
0
        }       //	SetLevel

        /// <summary>
        /// Publish
        /// Logging.Handler#Publish()
        /// </summary>
        /// <param name="record"></param>
        public override void Publish(LogRecord record)
        {
            if (!IsLoggable(record) || m_logs == null)
            {
                return;
            }

            //	Output
            lock (m_logs)
            {
                if (m_logs.Count >= LOG_SIZE)
                {
                    m_logs.RemoveFirst();
                }
                m_logs.AddLast(record);
            }

            //	We have an error
            if (record.GetLevel() == Level.SEVERE)
            {
                if (m_errors.Count >= ERROR_SIZE)
                {
                    m_errors.RemoveFirst();
                    m_history.RemoveFirst();
                }
                //	Add Error
                m_errors.AddLast(record);
                //record.sourceClassName;	//	forces Class Name eval

                //	Create History
                List <LogRecord> history = new List <LogRecord>();
                try
                {
                    foreach (LogRecord logr in m_logs)
                    {
                        LogRecord rec = (LogRecord)logr;
                        if (rec.GetLevel() == Level.SEVERE)
                        {
                            if (history.Count == 0)
                            {
                                history.Add(rec);
                            }
                            else
                            {
                                break;          //	don't incluse previous error
                            }
                        }
                        else
                        {
                            history.Add(rec);
                            if (history.Count > 10)
                            {
                                break;          //	no more then 10 history records
                            }
                        }
                    }
                }
                catch
                {
                }
                LogRecord[] historyArray = new LogRecord[history.Count];
                int         no           = 0;
                for (int i = history.Count - 1; i >= 0; i--)
                {
                    historyArray[no++] = (LogRecord)history[i];
                }
                m_history.AddLast(historyArray);
                //	Issue Reporting
                if (m_issueError)
                {
                    String loggerName = record.GetLoggerName();         //	class name
                    //	String className = record.getSourceClassName();		//	physical class
                    String methodName = record.sourceMethodName;        //
                    if (!methodName.Equals("SaveError") &&
                        !methodName.Equals("Get_Value") &&
                        !methodName.Equals("DataSave") &&
                        loggerName.IndexOf("Issue") == -1 &&
                        loggerName.IndexOf("CConnection") == -1
                        // && VAdvantage.DataBase.DB.IsConnected()
                        )
                    {
                        m_issueError = false;
                        //MIssue.create(record);
                        m_issueError = true;
                    }
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Log
 /// </summary>
 /// <param name="record">LogRecord</param>
 public new void Log(LogRecord record)
 {
     base.Log(record);
 }
コード例 #6
0
 /// <summary>
 /// Final Logging (Main Method)
 /// </summary>
 /// <param name="lr">LogRecord</param>
 private void DoLog(LogRecord lr)
 {
     lr.SetLoggerName(name);
     Log(lr);
 }
コード例 #7
0
        private Level logLevel = Level.ALL; //set the initial log level

        /// <summary>
        /// Publish a Log Record
        /// </summary>
        /// <param name="record">LogRecord which contains the msg</param>
        public abstract void Publish(LogRecord record);