示例#1
0
        private static string GetLogPath()
        {
            DateTime dateTime = TimeUtil.NowDateTime();

            lock (TwLogManager._PathLock)
            {
                string yearID  = dateTime.ToString("yyyy");
                string monthID = dateTime.ToString("MM");
                string dayID   = dateTime.ToString("dd");
                if (TwLogManager._TwLogPath == string.Empty || yearID != TwLogManager._YearID || monthID != TwLogManager._MonthID || dayID != TwLogManager._DayID)
                {
                    TwLogManager._YearID  = yearID;
                    TwLogManager._MonthID = monthID;
                    TwLogManager._DayID   = dayID;
                    try
                    {
                        TwLogManager.GetRootPath();
                        TwLogManager._TwLogPath = string.Format("{0}\\{1}{2}\\", TwLogManager._RootPath, TwLogManager._YearID, TwLogManager._MonthID);
                        if (!Directory.Exists(TwLogManager._TwLogPath))
                        {
                            Directory.CreateDirectory(TwLogManager._TwLogPath);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(TwLogManager._TwLogPath);
        }
示例#2
0
        public static void ScanLog()
        {
            string proID = TwLogManager.GetProductID();

            if (!(proID == "") && !(proID == "0"))
            {
                long nowTicks = TimeUtil.NOW();
                if (nowTicks - TwLogManager.LastScanTicks >= 600000L)
                {
                    TwLogManager.LastScanTicks = nowTicks;
                    string time     = TimeUtil.ConvertDateTimeInt(TimeUtil.NowDateTime()).ToString();
                    string num      = TwLogManager.GetOnLineNum().ToString();
                    string serverID = TwLogManager.GetServerID();
                    string log      = string.Format("{0}\t{1}\t{2}\t{3}\t{4}", new object[]
                    {
                        time,
                        num,
                        num,
                        proID,
                        serverID
                    });
                    TwLogManager.WriteLog(TwLogType.OnlineNum, log);
                }
            }
        }
示例#3
0
        public static void WriteLog(TwLogType logType, string logMsg)
        {
            DateTime now = TimeUtil.NowDateTime();

            lock (TwLogManager._FileLock)
            {
                LogFilePoolItem item;
                if (!TwLogManager.LogFilePoolList.TryGetValue(logType, out item))
                {
                    item = new LogFilePoolItem();
                    TwLogManager.LogFilePoolList.Add(logType, item);
                }
                if ((long)now.Hour != item.OpenTimeOnHours || (long)now.DayOfYear != item.OpenTimeOnDayOfYear || item._StreamWriter == null)
                {
                    if (null != item._StreamWriter)
                    {
                        item._StreamWriter.Close();
                        item._StreamWriter = null;
                    }
                    item._StreamWriter           = File.AppendText(TwLogManager.GetLogPath() + TwLogManager.GetFileName(logType));
                    item.OpenTimeOnHours         = (long)now.Hour;
                    item.OpenTimeOnDayOfYear     = (long)now.DayOfYear;
                    item._StreamWriter.AutoFlush = true;
                }
                try
                {
                    TwLogManager._StreamWriter = item._StreamWriter;
                    TwLogManager._StreamWriter.WriteLine(logMsg);
                }
                catch
                {
                }
            }
        }
示例#4
0
        public static string GetServerID()
        {
            string serverID;

            if (TwLogManager._ServerID != "")
            {
                serverID = TwLogManager._ServerID;
            }
            else
            {
                TwLogManager._ServerID = string.Format("{0}{1:000}", TwLogManager.GetProductID(), GameManager.ServerId);
                serverID = TwLogManager._ServerID;
            }
            return(serverID);
        }
示例#5
0
        private static string GetFileName(TwLogType type)
        {
            string name = "";

            switch (type)
            {
            case TwLogType.RoleCreate:
                name = string.Format("active_{0}_{1}_{2}{3}{4}.log", new object[]
                {
                    TwLogManager.GetProductID(),
                    TwLogManager.GetServerID(),
                    TwLogManager._YearID,
                    TwLogManager._MonthID,
                    TwLogManager._DayID
                });
                break;

            case TwLogType.RoleLogin:
                name = string.Format("login_{0}_{1}_{2}{3}{4}.log", new object[]
                {
                    TwLogManager.GetProductID(),
                    TwLogManager.GetServerID(),
                    TwLogManager._YearID,
                    TwLogManager._MonthID,
                    TwLogManager._DayID
                });
                break;

            case TwLogType.OnlineNum:
                name = string.Format("online_{0}_{1}_{2}{3}{4}.log", new object[]
                {
                    TwLogManager.GetProductID(),
                    TwLogManager.GetServerID(),
                    TwLogManager._YearID,
                    TwLogManager._MonthID,
                    TwLogManager._DayID
                });
                break;
            }
            return(name);
        }