Beispiel #1
0
        /// <summary>
        /// 添加异常日志
        /// </summary>
        /// <param name="message">额外异常信息</param>
        /// <param name="ex">异常对象</param>
        public void AppendException(string accesstoken, Exception ex, string message = "")
        {
            ExceptionEntity entry = new ExceptionEntity(message, ex);

            entry.AccessToken = accesstoken;
            LogSender.Append(entry);
        }
Beispiel #2
0
        /// <summary>
        /// 添加注册的日志
        /// </summary>
        /// <param name="accesstoken">当前注册用户的Accesstoken</param>
        /// <param name="registerMode">注册的模式</param>
        public void AppendRegister(int registerMode, string accesstoken)
        {
            //获取应用的AccessToken
            if (!HttpContext.Current.IsAvailable())
            {
                return;
            }
            if (String.IsNullOrEmpty(accesstoken))
            {
                return;
            }

            RegisterEntity entry = new RegisterEntity();

            entry.AccessToken  = accesstoken;
            entry.RegisterMode = registerMode;

            if (isDebug)
            {
                GathererLogger.Instance.Write(String.Format("Token:{0},RegisterMode:{1}",
                                                            accesstoken, registerMode));
            }

            LogSender.Append(entry);
        }
Beispiel #3
0
        /// <summary>
        /// 添加API调用日志
        /// </summary>
        /// <param name="callUrl">被调用API的地址</param>
        /// <param name="statusCode">调用结果状态码</param>
        /// <param name="callAppAccesstoken">调用接口的APP的AccessToken</param>
        /// <param name="requestSize">请求大小</param>
        /// <param name="responseTime">接口请求耗时</param>
        /// <param name="responseSize">接口请求大小</param>
        internal void AppendApiCall(string accesstoken, string callAccesstoken, int callAppId,
                                    string callUrl, int statusCode,
                                    long responseTime = 0, long requestSize = 0, long responseSize = 0)
        {
            try
            {
                ApiCallEntity entry = new ApiCallEntity
                {
                    AccessToken = accesstoken,
                    //这里做一个修改, 如果通过上面的方式都无法获取,则只使用AccessToken
                    CallAccessToken = String.IsNullOrEmpty(callAccesstoken) ?
                                      accesstoken : callAccesstoken,
                    CallAppId    = callAppId,
                    CallUrl      = callUrl,
                    StatusCode   = statusCode,
                    RequestSize  = requestSize,
                    ResponseSize = responseSize,
                    ResponseTime = responseTime,
                    TerminalCode = 1001
                };

                if (isDebug)
                {
                    GathererLogger.Instance.Write(String.Format("(API_CALL)Token:{0},CallAppId:{1},CallAccessToken:{2},CallUrl:{3},CallTimestamp:{4},IpAddress:{5}",
                                                                accesstoken, entry.CallAppId,
                                                                entry.CallAccessToken, callUrl,
                                                                entry.CallTimestamp.ToString(),
                                                                entry.IpAddress));
                }
                LogSender.Append(entry);
            }
            catch (Exception ex)
            {
                if (isDebug)
                {
                    GathererLogger.Instance.Write(String.Format("(API_CALL)Exception Occour! CallUrl:{0}, Message: {1}, Call Stack:{2}", callUrl, ex.Message, ex.StackTrace));
                    if (HttpContext.Current != null)
                    {
                        String queryString = String.Empty;
                        foreach (string key in HttpContext.Current.Request.QueryString.AllKeys)
                        {
                            queryString += String.Format("{0}={1}&", key, HttpContext.Current.Request.QueryString[key]);
                        }
                        GathererLogger.Instance.Write(String.Format("QueryString:{0}", queryString));
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 添加页面访问日志信息
        /// </summary>
        /// <param name="accesstoken">访问用户的AccessToken</param>
        /// <param name="visitePage">访问的页面</param>
        /// <param name="referPage">被应用的页面</param>
        /// <param name="pageParams">页面参数</param>
        internal void AppendPageVisit(string accesstoken, string visitePage, string referPage, NameValueCollection pageParams)
        {
            try
            {
                //获取应用的AccessToken
                if (!HttpContext.Current.IsAvailable())
                {
                    return;
                }
                //如果获取到的AccessToken为空, 本次的请求就放弃掉
                if (String.IsNullOrEmpty(accesstoken))
                {
                    return;
                }

                PageVisitEntity entry = new PageVisitEntity();
                entry.ParsePageParams(pageParams);
                entry.AccessToken = accesstoken;
                entry.VisitPage   = visitePage;
                entry.ReferPage   = referPage;

                if (isDebug)
                {
                    GathererLogger.Instance.Write(String.Format("(PAGE_VISITE)Token:{0},VisitPage:{1},ReferPage:{2},CallTimestamp:{3}",
                                                                accesstoken, entry.VisitPage,
                                                                entry.ReferPage, entry.CallTimestamp.ToString()));
                }
                LogSender.Append(entry);
            }
            catch (Exception ex)
            {
                if (isDebug)
                {
                    GathererLogger.Instance.Write(String.Format("(PAGE_VISITE)Exception Occour! CallUrl:{0}, Message: {1}, Call Stack:{2}", visitePage, ex.Message, ex.StackTrace));
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// 添加自定义日志类型
 /// </summary>
 /// <param name="entry">自定义的日志实体,<see cref="LogEntity"/></param>
 public void Append(LogEntity entry)
 {
     LogSender.Append(entry);
 }