Beispiel #1
0
        /// <summary>
        /// Write the text representation of the specified array of objects to
        /// server log agent using the specified format information.
        /// </summary>
        /// <param name="display">Shall the representation be displayed in the console window.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="arg">An array of objects to write using format.</param>
        public void WriteLine(bool display, string format, params object[] arg)
        {
            string str;
            string timestamp;

            if (FirstTime)
            {
                timestamp = string.Format("{0}+0", BeginTime.ToString("HH:mm:ss.fff")); FirstTime = false;
            }
            else
            {
                timestamp = GetTime(BeginTime);
            }

            if (timestamp.Length < 20)            //15:55:58.283+7600010 = 20 character long
            {
                str = string.Format("{0}+0\t\t{1}", BeginTime.ToString("HH:mm:ss.fff"), string.Format(format, arg));
                LogAgent.WriteLine(str, display, false);
                str = string.Format("{0}+0\t{1}", BeginTime.ToString("HH:mm:ss.fff"), string.Format(format, arg));
                LogAgent.WriteLine(str, false, true);
            }
            else
            {
                str = string.Format("{0}\t{1}", GetTime(BeginTime), string.Format(format, arg));
                LogAgent.WriteLine(str, display);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Write the text representation of the specified array of objects to
        /// server log agent using the specified format information.
        /// </summary>
        /// <param name="display">Shall the representation be displayed in the console window.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="arg">An array of objects to write using format.</param>
        public void WriteLine(bool display, bool displayTimestamp, string format, params object[] arg)
        {
            string str;
            string timestamp;
            string message = string.Format(format, arg);

            if (FirstTime)
            {
                timestamp = string.Format("{0}+0", BeginTime.ToString("dd.MM.yyyy HH:mm:ss.fff")); FirstTime = false;
            }
            else
            {
                timestamp = GetTime(BeginTime);
            }

            if (displayTimestamp)            //e.g. ">GET http://example.com/ (127.0.0.1)"
            {
                if (timestamp.Length < 20)   //23.02.2021 15:55:58.283+7600010 = 31 character long
                {
                    str = string.Format("{0}+0\t\t{1}", BeginTime.ToString("dd.MM.yyyy HH:mm:ss.fff"), message);
                    LogAgent.WriteLine(str, display, false);
                    str = string.Format("{0}+0\t{1}", BeginTime.ToString("dd.MM.yyyy HH:mm:ss.fff"), message);
                    LogAgent.WriteLine(str, false, true);
                }
                else
                {
                    str = string.Format("{0}\t{1}", GetTime(BeginTime), message);
                    LogAgent.WriteLine(str, true, display);
                }
            }

            else             //e.g. "Starting server..."
            {
                str = string.Format("{0}+0\t{1}", BeginTime.ToString("dd.MM.yyyy HH:mm:ss.fff"), message);

                LogAgent.WriteLine(str, display, true, message);
                return;
            }
        }