Exemplo n.º 1
0
        private static void Log(string severity, string pattern, params object[] args)
        {
            if (!_mLogEnable)
            {
                return;
            }
            lock (_mWiterLock)
            {
                try
                {
                    string timestamp = new DateTime(MilliSecondTimer.CurrentTimeMicros() * 10L).ToString("yyyy-MM-dd HH:mm:ss.fff");
                    string message   = string.Format(pattern, args);
                    string line      = "[" + timestamp + "] [" + severity + "] " + message;

                    StreamWriter writer = GetWriter();
                    if (_mWriter != null)
                    {
                        _mWriter.WriteLine(line);
                        _mWriter.Flush();
                    }
                    else
                    {
                        Console.WriteLine(line);
                    }
                }
                catch (Exception e)
                {
                    Cat.lastException = e;
                }
            }
        }
Exemplo n.º 2
0
        private static StreamWriter GetWriter()
        {
            string path = new DateTime(MilliSecondTimer.CurrentTimeMicros() * 10L).ToString("yyyyMMdd");

            if (!path.Equals(_mLastPath))
            {
                if (_mWriter != null)
                {
                    try
                    {
                        _mWriter.Close();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Cat.lastException = e;
                    }
                }

                string logFile = "cat_" + _mDomain + "_" + path + ".log";

                try
                {
                    if (Directory.Exists(CatConstants.CAT_HOME_TEMP) && isWritable(CatConstants.CAT_HOME_TEMP))
                    {
                        _mWriter = new StreamWriter(Path.Combine(CatConstants.CAT_HOME_TEMP, logFile), true);
                        Console.WriteLine("Logger file " + Path.Combine(CatConstants.CAT_HOME_TEMP, logFile));
                    }
                    else if (Directory.Exists(CatConstants.CAT_HOME) && isWritable(CatConstants.CAT_HOME))
                    {
                        _mWriter = new StreamWriter(Path.Combine(CatConstants.CAT_HOME, logFile), true);
                        Console.WriteLine("Logger file " + Path.Combine(CatConstants.CAT_HOME, logFile));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error when openning log file: " + e.Message + " " + e.StackTrace + ".");
                    Cat.lastException = e;
                }
            }

            _mLastPath = path;
            return(_mWriter);
        }