/// <summary>
        ///     构造函数
        /// </summary>
        /// <param name="exception"></param>
        public ExceptionLogHandler(Exception exception) : base("ExceptionLogToDatabase")
        {
            PrincipalUser principalUser = new PrincipalUser();
            var           current       = HttpContexts.Current;

            if (current != null)
            {
                principalUser = AuthenticationExtension.Current();
            }
            if (principalUser == null)
            {
                principalUser = new PrincipalUser()
                {
                    Name   = "匿名用户",
                    UserId = Guid.Empty
                };
            }
            log = new ExceptionLog()
            {
                ExceptionLogId = CombUtil.NewComb().ToString(),
                CreateUserCode = principalUser.Code,
                CreateUserId   = principalUser.UserId.ToString(),
                CreateUserName = principalUser.Name,
                ServerHost     = String.Format("{0}【{1}】", IpBrowserUtil.GetServerHost(), IpBrowserUtil.GetServerHostIp()),
                ClientHost     = String.Format("{0}", IpBrowserUtil.GetClientIp()),
                Runtime        = "Web",
                CreateTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Message        = exception.Message,
                StackTrace     = exception.StackTrace,
                ExceptionType  = exception.GetType().FullName,
                ClientAddress  = IpBrowserUtil.GetAddressByApi()
            };
            //获取服务器信息
            var request = HttpContexts.Current.Request;

            log.RequestUrl     = string.Format("{0} ", request.Path);
            log.HttpMethod     = request.Method;
            log.UserAgent      = request.Headers["user-agent"];
            log.InnerException = exception.InnerException != null?GetExceptionFullMessage(exception.InnerException) : "";

            if (request?.HasFormContentType ?? request.HasFormContentType)
            {
                log.RequestData = request?.Form?.ToJson();
            }
            else
            {
                if (request.Body.CanSeek)
                {
                    log.RequestData = HttpUtility.UrlDecode(new StreamReader(request?.Body).ReadToEnd());
                }
            }
        }
示例#2
0
 public LoginLogHandler(string userId, string code, string userName, int loginStatus) : base("LoginLogToDatabase")
 {
     log =
         new LoginLog
     {
         Id             = CombUtil.NewComb(),
         CreateUserId   = userId,
         CreateUserCode = code ?? "",
         ServerHost     = $"{IpBrowserUtil.GetServerHost()}【{IpBrowserUtil.GetServerHostIp()}】",
         ClientHost     = $"{IpBrowserUtil.GetClientIp()}",
         UserAgent      = IpBrowserUtil.GetBrowser(),
         OsVersion      = IpBrowserUtil.GetOsVersion(),
         LoginTime      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
         IpAddressName  = IpBrowserUtil.GetAddressByApi(),
         CreateTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
         CreateUserName = userName,
         LoginStatus    = loginStatus
     };
 }
 public LoginLogHandler(string UserId, string Code, string UserName, int LoginStatus) : base("LoginLogToDatabase")
 {
     log =
         new LoginLog
     {
         LoginLogId     = CombUtil.NewComb().ToString(),
         CreateUserId   = UserId,
         CreateUserCode = Code ?? "",
         ServerHost     = String.Format("{0}【{1}】", IpBrowserUtil.GetServerHost(), IpBrowserUtil.GetServerHostIp()),
         ClientHost     = String.Format("{0}", IpBrowserUtil.GetClientIp()),
         UserAgent      = IpBrowserUtil.GetBrowser(),
         OsVersion      = IpBrowserUtil.GetOsVersion(),
         LoginTime      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
         IpAddressName  = IpBrowserUtil.GetAddressByApi(),
         CreateTime     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
         CreateUserName = UserName,
         LoginStatus    = LoginStatus
     };
 }
示例#4
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="loginLogId">登录Id</param>
        public LoginLogHandler(Guid loginLogId)
            : base("LoginLogToDatabase")
        {
            PrincipalUser principalUser = new PrincipalUser
            {
                Name   = "匿名用户",
                UserId = Guid.Empty
            };
            var current = HttpContext.Current;

            if (current != null)
            {
                principalUser = FormAuthenticationExtension.Current(HttpContext.Current.Request);
            }
            if (principalUser == null)
            {
                principalUser = new PrincipalUser()
                {
                    Name   = "匿名用户",
                    UserId = Guid.Empty
                };
            }
            var request = HttpContext.Current.Request;

            log = new LoginLog
            {
                LoginLogId     = loginLogId,
                CreateUserId   = principalUser.UserId,
                CreateUserCode = principalUser.Code ?? "",
                CreateUserName = principalUser.Name,
                ServerHost     = String.Format("{0}【{1}】", IpBrowserUtil.GetServerHost(), IpBrowserUtil.GetServerHostIp()),
                ClientHost     = String.Format("{0}", IpBrowserUtil.GetClientIp()),
                UserAgent      = request.Browser.Browser + "【" + request.Browser.Version + "】",
                OsVersion      = IpBrowserUtil.GetOsVersion(),
                LoginTime      = DateTime.Now,
                IpAddressName  = IpBrowserUtil.GetAddressByApi()
            };
            //根据提供的api接口获取登录物理地址:http://whois.pconline.com.cn/
        }