Пример #1
0
        // Log 500 errors
        public async Task LogInternalServerException(ExceptionContext context)
        {
            string username = "******";
            string userId   = "ANONYMOUS";

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                userId   = HttpContext.User.Identity.Name;
                username = _context.Users.Where(x => x.Id.Equals(userId)).SingleOrDefault().Email;
            }

            string domain  = HttpContext.Request.Host.Value;
            string pageUrl = string.Format("{0}://{1}{2}{3}",
                                           HttpContext.Request.Scheme,
                                           HttpContext.Request.Host,
                                           HttpContext.Request.Path,
                                           HttpContext.Request.QueryString);
            string ipAddress = _clientIP.GetClientIP();

            try
            {
                await _context.SiteException.AddAsync(new SiteException
                {
                    CreateDate = DateTime.UtcNow,
                    Exception  = context.Exception.ToString(),
                    IpAddress  = ipAddress,
                    PageUrl    = pageUrl,
                    UserId     = userId
                });

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                await _email.SendEmailAsync("*****@*****.**", "*****@*****.**", "[탈조선] SiteException 추가 오류", ex.ToString(), null);
            }

            string subject = "[탈조선] 500 오류";
            string body    = "Domain: " + domain + "\r\n\r\n"
                             + "Page Url: " + pageUrl + "\r\n\r\n"
                             + "Username: "******"\r\n\r\n"
                             + "IP Address: " + ipAddress + "\r\n\r\n"
                             + "Exception: " + context.Exception.Message + "\r\n\r\n"
                             + "StackTrace: " + context.Exception.StackTrace + "\r\n\r\n"
                             + "Inputs: " + "\r\n\r\n";

            if (HttpContext.Request.HasFormContentType)
            {
                var form = HttpContext.Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
                foreach (KeyValuePair <string, string> entry in form)
                {
                    body += "Control: " + entry.Key + "; Value: " + entry.Value + "\r\n";
                }
            }

            //await _email.SendEmailAsync("*****@*****.**", "*****@*****.**", subject, body, null);
        }
        public async Task LogWithdrewUser(string reason, ApplicationUser user)
        {
            WithdrawUser withdrawUser = new WithdrawUser
            {
                Email        = user.Email,
                NickName     = user.NickName,
                Reason       = reason,
                DateWithdrew = DateTime.UtcNow
            };

            await _context.WithdrawUser.AddAsync(withdrawUser);

            await _context.SaveChangesAsync();
        }
 public virtual async Task CommitAsync()
 {
     await _context.SaveChangesAsync();
 }