private AdvException GetError(Debug.ErrType errType, string atTime)
 {
     try
     {
         if (File.Exists(Debug.ErrFile[errType]))
         {
             using (var csv = new CsvHelper.CsvReader(new StreamReader(Debug.ErrFile[errType], Encoding.UTF8, true)))
             {
                 csv.Configuration.Delimiter       = Debug.CharSeparate;
                 csv.Configuration.HasHeaderRecord = false;
                 while (csv.Read())
                 {
                     string[] r = csv.CurrentRecord;
                     if (atTime == r[0] && r.Length >= 5)
                     {
                         var ex1 = AdvException.GetFromJsonString(r[4]);
                         ex1.ExceptionData.ManualMessage = r[2];
                         return(ex1);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         lblErr.Text = ex.Message;
     }
     return(null);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblErr.Text = string.Empty;
            SetMeta(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Admin_MasterPageAdmin_BugTracker_HeaderDetails));
            hfBack.NavigateUrl = "LogViewer.aspx";
            if (string.IsNullOrWhiteSpace(Request["attime"]) || string.IsNullOrWhiteSpace(Request["errtype"]))
            {
                lblErr.Text = @"Request wrong";
                return;
            }

            _atTime = HttpUtility.UrlDecode(Request["attime"]);

            Enum.TryParse(Request["errtype"], true, out _currentView);
            if (_currentView == Debug.ErrType.None)
            {
                lblErr.Text = @"Wrong ErrType";
                return;
            }
            hfBack.NavigateUrl = "LogViewer.aspx?ErrType=" + _currentView.ToString();

            _curError = GetError(_currentView, _atTime);
            if (_curError != null)
            {
                ValidRequst = true;
                //common
                OutHtml.Append("<div class=\'tab-content\'>");
                OutHtml.Append("<table>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Date", _atTime);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Message", _curError.ExceptionData.ManualMessage.IsNullOrEmpty() ? "none" : _curError.ExceptionData.ManualMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionMessage", _curError.ExceptionData.ExceptionMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionStackTrace", _curError.ExceptionData.ExceptionStackTrace.IsNullOrEmpty() ? "none" : _curError.ExceptionData.ExceptionStackTrace);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionMessage", _curError.ExceptionData.InnerExceptionMessage.IsNullOrEmpty() ? "none" : _curError.ExceptionData.InnerExceptionMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionStackTrace", _curError.ExceptionData.InnerExceptionStackTrace.IsNullOrEmpty() ? "none" : _curError.ExceptionData.InnerExceptionStackTrace);

                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                foreach (var key in _curError.ExceptionData.Parameters.Keys)
                {
                    OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.ExceptionData.Parameters[key]);
                }

                OutHtml.Append("</table>");
                OutHtml.Append("</div>");

                //request
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.RequestData != null)
                {
                    OutHtml.Append("<table>");

                    foreach (var key in _curError.RequestData.ColectionData.Keys)
                    {
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.RequestData.ColectionData[key]);
                    }
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");

                //browser
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.BrowserData != null)
                {
                    OutHtml.Append("<table>");
                    foreach (var key in _curError.BrowserData.ColectionData.Keys)
                    {
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.BrowserData.ColectionData[key]);
                    }
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");

                //session
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.SessionData != null)
                {
                    OutHtml.Append("<table>");
                    foreach (var key in _curError.SessionData.ColectionData.Keys)
                    {
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.SessionData.ColectionData[key]);
                    }
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");
            }
        }
Example #3
0
        //public static bool SetCoreConfigSettingValue(string strKey, string strValue)
        //{
        //    throw (new NotImplementedException());
        //}
        private static void WriteMessage(string message, Exception exception, bool sendEmail)
        {
            var mLog = new StringBuilder();
            mLog.Append(message);
            mLog.Append(CharSeparate);
            AdvException currError = null;
            if (exception != null)
            {
                mLog.AppendFormat("\"{0}\";", exception.Message);
                currError = new AdvException(exception);
                mLog.AppendFormat("\"{0}\";", currError.ToJsonString().Replace("\"", "\"\""));
            }
            else
            {
                mLog.Append("none;none;");
            }

            var hex = exception as HttpException;
            var code = hex != null ? hex.GetHttpCode() : 0;

            switch (code)
            {
                case 0:
                    LogErrHttp.Error(mLog.ToString());
                    break;
                case 404:
                    LogErr404.Error(mLog.ToString());
                    break;
                case 500:
                    LogErr500.Error(mLog.ToString());
                    break;
                default:
                    LogErrHttp.Error(mLog.ToString());
                    break;
            }

            // Send email
            if (EnableErrorMailNotification && code != 404 && sendEmail)
            {
                if (currError != null)
                    SendMailError(currError);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblErr.Text = string.Empty;
            SetMeta(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Admin_MasterPageAdmin_BugTracker_HeaderDetails));
            hfBack.NavigateUrl = "LogViewer.aspx";
            if (string.IsNullOrWhiteSpace(Request["attime"]) || string.IsNullOrWhiteSpace(Request["errtype"]))
            {
                lblErr.Text = @"Request wrong";
                return;
            }

            _atTime = HttpUtility.UrlDecode(Request["attime"]);

            Enum.TryParse(Request["errtype"], true, out _currentView);
            if (_currentView == Debug.ErrType.None)
            {
                lblErr.Text = @"Wrong ErrType";
                return;
            }
            hfBack.NavigateUrl = "LogViewer.aspx?ErrType=" + _currentView.ToString();

            _curError = GetError(_currentView, _atTime);
            if (_curError != null)
            {
                ValidRequst = true;
                //common
                OutHtml.Append("<div class=\'tab-content\'>");
                OutHtml.Append("<table>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Date", _atTime);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Message", _curError.ExceptionData.ManualMessage.IsNullOrEmpty() ? "none" : _curError.ExceptionData.ManualMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionMessage", _curError.ExceptionData.ExceptionMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionStackTrace", _curError.ExceptionData.ExceptionStackTrace.IsNullOrEmpty() ? "none" : _curError.ExceptionData.ExceptionStackTrace);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionMessage", _curError.ExceptionData.InnerExceptionMessage.IsNullOrEmpty() ? "none" : _curError.ExceptionData.InnerExceptionMessage);
                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionStackTrace", _curError.ExceptionData.InnerExceptionStackTrace.IsNullOrEmpty() ? "none" : _curError.ExceptionData.InnerExceptionStackTrace);

                OutHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                foreach (var key in _curError.ExceptionData.Parameters.Keys)
                    OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.ExceptionData.Parameters[key]);

                OutHtml.Append("</table>");
                OutHtml.Append("</div>");

                //request
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.RequestData != null)
                {
                    OutHtml.Append("<table>");

                    foreach (var key in _curError.RequestData.ColectionData.Keys)
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.RequestData.ColectionData[key]);
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");

                //browser
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.BrowserData != null)
                {
                    OutHtml.Append("<table>");
                    foreach (var key in _curError.BrowserData.ColectionData.Keys)
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.BrowserData.ColectionData[key]);
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");

                //session
                OutHtml.Append("<div class=\'tab-content\'>");
                if (_curError.SessionData != null)
                {
                    OutHtml.Append("<table>");
                    foreach (var key in _curError.SessionData.ColectionData.Keys)
                        OutHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, _curError.SessionData.ColectionData[key]);
                    OutHtml.Append("</table>");
                }
                OutHtml.Append("</div>");
            }
        }
Example #5
0
        private static void SendMailError(AdvException currError)
        {
            if (HttpContext.Current != null && HttpContext.Current.Request.Url.AbsoluteUri.Contains("localhost")) return;

            lock (Sync)
            {
                var data = LogTempDataService.GetLogTempData();
                if (data.MailErrorLastSend.DayOfYear < DateTime.Now.DayOfYear) data.MailErrorCurrentCount = 0;
                if (data.MailErrorCurrentCount < MaxMailsSendPerDay)
                {

                    if (File.Exists(EmailNotificationTemplate))
                    {
                        var template = new StringBuilder(File.ReadAllText(EmailNotificationTemplate));

                        template.Replace("CommonInfo_Header", Resource.Admin_MasterPageAdmin_BugTracker_CommonInfo);
                        var outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        outHtml.Append("<table>");
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Message", currError.ExceptionData.ManualMessage.IsNullOrEmpty() ? "none" : currError.ExceptionData.ManualMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionMessage", currError.ExceptionData.ExceptionMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionStackTrace", currError.ExceptionData.ExceptionStackTrace.IsNullOrEmpty() ? "none" : currError.ExceptionData.ExceptionStackTrace);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionMessage", currError.ExceptionData.InnerExceptionMessage.IsNullOrEmpty() ? "none" : currError.ExceptionData.InnerExceptionMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionStackTrace", currError.ExceptionData.InnerExceptionStackTrace.IsNullOrEmpty() ? "none" : currError.ExceptionData.InnerExceptionStackTrace);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        foreach (var key in currError.ExceptionData.Parameters.Keys)
                            outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.ExceptionData.Parameters[key]);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");

                        outHtml.Append("</table>");
                        outHtml.Append("</div>");
                        template.Replace("CommonInfo_Body", outHtml.ToString());

                        template.Replace("Request_Header", Resource.Admin_MasterPageAdmin_BugTracker_Request);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.RequestData != null)
                        {
                            outHtml.Append("<table>");

                            foreach (var key in currError.RequestData.ColectionData.Keys)
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.RequestData.ColectionData[key]);
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Request_Body", outHtml.ToString());

                        template.Replace("Browser_Header", Resource.Admin_MasterPageAdmin_BugTracker_Browser);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.BrowserData != null)
                        {
                            outHtml.Append("<table>");
                            foreach (var key in currError.BrowserData.ColectionData.Keys)
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.BrowserData.ColectionData[key]);
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Browser_Body", outHtml.ToString());

                        template.Replace("Session_Header", Resource.Admin_MasterPageAdmin_BugTracker_Session);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.SessionData != null)
                        {
                            outHtml.Append("<table>");
                            foreach (var key in currError.SessionData.ColectionData.Keys)
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.SessionData.ColectionData[key]);
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Session_Body", outHtml.ToString());

                        ILoggerRepository rep = LogManager.GetRepository();
                        foreach (IAppender appender in rep.GetAppenders())
                        {
                            if (appender is SmtpAppender)
                            {
                                // Loop exception here. SettingsMain.SiteUrl - Лезет в базу.
                                // ((SmtpAppender)appender).Subject = SettingsMain.SiteUrl + " " + SettingsGeneral.SiteVersion;

                                ((SmtpAppender)appender).Subject = SettingsGeneral.AbsoluteUrl + " " + SettingsGeneral.SiteVersion;
                                var emailLog1 = LogManager.GetLogger("EmailErr");
                                emailLog1.Error(template.ToString());
                            }
                        }
                    }

                    data.MailErrorCurrentCount++;
                    data.MailErrorLastSend = DateTime.Now;
                }
                LogTempDataService.UpdateLogTempData(data);
            }
        }