protected void Application_Error(object sender, EventArgs e)
        {
            OnCustomEndRequest(sender, e);
            try
            {
                if (Context != null && Context.AllErrors != null)
                {
                    WebInitializer.Initialize();
                    var monitor = new LogMonitor();
                    monitor.Init();
                    var str2 = Tools.Security.User.GetSID();
                    var db   = new DBFilterValuesDataContext(SpecificInstances.DbFactory.CreateConnection());

                    // присвоение выбранного фильтра, для его пометки, как опасного
                    long?refUserFilter = null;
                    if (MainPageUrlBuilder.Current.IsDataControl &&
                        MainPageUrlBuilder.Current.UserControl != null &&
                        MainPageUrlBuilder.Current.UserControl.EndsWith("Journal"))
                    {
                        var tableName    = MainPageUrlBuilder.Current.UserControl.Substring(0, MainPageUrlBuilder.Current.UserControl.Length - 7);
                        var filterValues = MainPageUrlBuilder.Current.GetFilterItemsDic(tableName);
                        if (filterValues != null && filterValues.ContainsKey("__refUserFilterValues") &&
                            filterValues["__refUserFilterValues"].Count > 0 &&
                            !string.IsNullOrEmpty(filterValues["__refUserFilterValues"][0].Value1))
                        {
                            refUserFilter = Convert.ToInt64(filterValues["__refUserFilterValues"][0].Value1);
                        }
                    }

                    foreach (var exception in Context.AllErrors)
                    {
                        var message = string.Format("{0}: {1}", Context.Request.Url.PathAndQuery, exception);
                        var entry2  = new LogMessageEntry(LogMessageType.SystemErrorInApp, message)
                        {
                            Sid = str2
                        };
                        var logMessageEntry = entry2;
                        var refLog          = monitor.WriteLog(logMessageEntry);
                        // для ошибок дополнительно залогируем агрументы
                        if (Context.Request.HttpMethod.ToLower() == "post" && refLog != null)
                        {
                            foreach (string key in Context.Request.Form.Keys)
                            {
                                monitor.WriteFieldChanged(refLog.Value, "", key, Context.Request.Form[key], null);
                            }
                        }

                        var sqlException = exception as SqlException ?? exception.InnerException as SqlException;
                        if (sqlException != null && refUserFilter != null)
                        {
                            foreach (SqlError sqlError in sqlException.Errors)
                            {
                                if (sqlError.Number == -2)
                                {
                                    db.SYS_SetIsDangerousUserFilter(refUserFilter);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 public long?WriteLog(ILogMessageEntry logMessageEntry)
 {
     return(logMonitor.WriteLog(logMessageEntry));
 }