Exemplo n.º 1
0
        public static void Write(string content, string path)
        {
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.Append(System.DateTime.Now);
            stringBuilder.Append(" 源:" + GameRequest.GetRawUrl());
            stringBuilder.Append(" IP:" + GameRequest.GetUserIP());
            stringBuilder.Append(" 描述:" + content + "\r\n");
            string mapPath = TextUtility.GetMapPath("/Log/Error/");

            if (!System.IO.Directory.Exists(mapPath))
            {
                System.IO.Directory.CreateDirectory(mapPath);
            }
            string text = mapPath + path + ".log";
            int    num  = 0;

            text = FileManager.GetCurrentLogName(mapPath, text, ref num);
            if (System.IO.File.Exists(text))
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(text);
                if (fileInfo.Length > 31457280L)
                {
                    text = string.Concat(new object[]
                    {
                        mapPath,
                        path,
                        "[",
                        num,
                        "].log"
                    });
                }
            }
            System.IO.File.AppendAllText(text, stringBuilder.ToString(), System.Text.Encoding.Unicode);
        }
Exemplo n.º 2
0
        public static void Write(string content)
        {
            string key = "LastWritErrorLogTime";
            object obj = WHCache.Default.Get <AspNetCache>(key);

            if (obj == null || (System.DateTime.Now - System.Convert.ToDateTime(obj)).TotalMilliseconds > 20.0)
            {
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                stringBuilder.Append(System.DateTime.Now);
                stringBuilder.Append(" 源:" + GameRequest.GetRawUrl());
                stringBuilder.Append(" IP:" + GameRequest.GetUserIP());
                stringBuilder.Append(" 描述:" + content + "\r\n");
                string mapPath = TextUtility.GetMapPath("/Log/Error/");
                if (!System.IO.Directory.Exists(mapPath))
                {
                    System.IO.Directory.CreateDirectory(mapPath);
                }
                string text = mapPath + "ErrorLog" + System.DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                int    num  = 0;
                text = FileManager.GetCurrentLogName(mapPath, text, ref num);
                if (System.IO.File.Exists(text))
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(text);
                    if (fileInfo.Length > 31457280L)
                    {
                        text = string.Concat(new object[]
                        {
                            mapPath,
                            "ErrorLog",
                            System.DateTime.Now.ToString("yyyy-MM-dd"),
                            "[",
                            num,
                            "].log"
                        });
                    }
                }
                System.IO.File.AppendAllText(text, stringBuilder.ToString(), System.Text.Encoding.Unicode);
                WHCache.Default.Save <AspNetCache>(key, System.DateTime.Now, new int?(1));
            }
        }
Exemplo n.º 3
0
        public static void Write(string content)
        {
            // 判断距离上一次写入的日志时间
            string key = "LastWritErrorLogTime";
            object obj = WHCache.Default.Get <AspNetCache>(key);

            if (obj == null || (DateTime.Now - Convert.ToDateTime(obj)).TotalMilliseconds > TimeInterval)
            {
                // 日志内容
                StringBuilder log = new StringBuilder();
                log.Append(DateTime.Now);
                log.Append(" 源:" + GameRequest.GetRawUrl());
                log.Append(" IP:" + GameRequest.GetUserIP());
                log.Append(" 描述:" + content + "\r\n");

                // 检查目录
                string directory = Game.Utils.TextUtility.GetMapPath(LogFilePath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                // 检查当前日志文件大小 超过30M则创建一个新的日志文件
                string fullPath = directory + "ErrorLog" + DateTime.Now.ToString("yyyy-MM") + ".log";
                int    i        = 0;
                fullPath = FileManager.GetCurrentLogName(directory, fullPath, ref i);
                if (File.Exists(fullPath))
                {
                    FileInfo fi = new FileInfo(fullPath);
                    if (fi.Length > 30 * 1024 * 1024)
                    {
                        fullPath = directory + "ErrorLog" + DateTime.Now.ToString("yyyy-MM") + "[" + i + "].log";
                    }
                }

                // 写入日志
                File.AppendAllText(fullPath, log.ToString(), System.Text.Encoding.Unicode);
                WHCache.Default.Save <AspNetCache>(key, DateTime.Now, 1);
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //是否登录
            if (Fetch.GetUserCookie() == null)
            {
                divLogon.Visible   = false;
                divNoLogon.Visible = true;
                returnUrl          = GameRequest.GetRawUrl();
                return;
            }

            //查询帐号
            UserInfo userInfo = FacadeManage.aideAccountsFacade.GetUserGlobalInfo(Fetch.GetUserCookie().UserID, 0, "").EntityList[0] as UserInfo;

            if (userInfo == null)
            {
                divLogon.Visible   = false;
                divNoLogon.Visible = true;
                return;
            }
            faceUrl  = FacadeManage.aideAccountsFacade.GetUserFaceUrl(userInfo.FaceID, userInfo.CustomID);
            accounts = userInfo.Accounts;
            medal    = userInfo.UserMedal;
        }
Exemplo n.º 5
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     if (Fetch.GetUserCookie() == null)
     {
         this.divLogon.Visible   = false;
         this.divNoLogon.Visible = true;
         this.returnUrl          = GameRequest.GetRawUrl();
     }
     else
     {
         UserInfo userInfo = FacadeManage.aideAccountsFacade.GetUserGlobalInfo(Fetch.GetUserCookie().UserID, 0, "").EntityList[0] as UserInfo;
         if (userInfo == null)
         {
             this.divLogon.Visible   = false;
             this.divNoLogon.Visible = true;
         }
         else
         {
             this.faceUrl  = FacadeManage.aideAccountsFacade.GetUserFaceUrl((int)userInfo.FaceID, userInfo.CustomID);
             this.accounts = userInfo.Accounts;
             this.medal    = userInfo.UserMedal;
         }
     }
 }
Exemplo n.º 6
0
        private void Application_OnError(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     context         = httpApplication.Context;
            Exception       ex = context.Server.GetLastError();

            if (ex is HttpException)
            {
                HttpException ex2 = ex as HttpException;
                if (ex2.GetHttpCode() == 404)
                {
                    string physicalPath = httpApplication.Request.PhysicalPath;
                    TextLogger.Write(string.Format("文件不存在:{0}", httpApplication.Request.Url.AbsoluteUri));
                    return;
                }
            }
            if (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }
            StringBuilder stringBuilder = new StringBuilder().AppendFormat("访问路径:{0}", GameRequest.GetRawUrl()).AppendLine().AppendFormat("{0} thrown {1}", ex.Source, ex.GetType().ToString())
                                          .AppendLine()
                                          .Append(ex.Message)
                                          .Append(ex.StackTrace);

            TextLogger.Write(stringBuilder.ToString());
        }