Ejemplo n.º 1
0
        public static void LogCommand(SqlCommand Command, bool Success)
        {
            if (Command == null || !IsLoggable(Command.CommandText))
            {
                return;
            }
            try
            {
                CommandDetail oDetail = new CommandDetail();

                oDetail.CommandText      = Command.CommandText;
                oDetail.ParameterDetails = Util.GetSqlCommandDetails(Command, false, true);
                oDetail.Success          = Success;
                System.Web.HttpContext oContext = System.Web.HttpContext.Current;

                if (oContext != null)
                {
                    if (oContext.Session["LoggableEditorID"] != null)
                    {
                        oDetail.EditorID = Convert.ToInt32(oContext.Session["LoggableEditorID"]);
                    }

                    if (oContext.Session["LoggableUserID"] != null)
                    {
                        oDetail.UserID = Convert.ToInt32(oContext.Session["LoggableUserID"]);
                    }

                    if (oContext.Session["LoggableUserType"] != null)
                    {
                        oDetail.UserType = 0;
                    }
                }
                LogCommand(oDetail);
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(new Exception("LogCommand loglayamadý: ", ex));
            }
        }
Ejemplo n.º 2
0
        private static void LogCommand(CommandDetail oDetail)
        {
            try
            {
                SqlParameter oUserID           = new SqlParameter("@UserID", SqlDbType.Int);
                SqlParameter oEditorID         = new SqlParameter("@EditorID", SqlDbType.Int);
                SqlParameter oUserType         = new SqlParameter("@UserType", SqlDbType.Int);
                SqlParameter oCommandText      = new SqlParameter("@CommandText", SqlDbType.VarChar);
                SqlParameter oParameterDetails = new SqlParameter("@ParameterDetails", SqlDbType.VarChar);
                SqlParameter oSuccess          = new SqlParameter("@Success", SqlDbType.Bit);

                oUserID.Value           = oDetail.UserID;
                oEditorID.Value         = oDetail.EditorID;
                oUserType.Value         = Convert.ToInt32(oDetail.UserType);
                oCommandText.Value      = oDetail.CommandText;
                oParameterDetails.Value = oDetail.ParameterDetails;
                oSuccess.Value          = oDetail.Success ? 1 : 0;

                SqlParameter[] arrParameters = { oUserID, oEditorID, oUserType, oCommandText, oParameterDetails, oSuccess };

                SqlHelper.ExecuteNonQuery(ConfigManager.Current.ConnectionString, CommandType.StoredProcedure, "LogCommandDetails", arrParameters);
                if (oDetail.Success == false)
                {
                    string Detail = string.Format(@"CommandLogger-Success=0<br>
UserID={0}<br>
UserType={1}<br>
EditorID={2}<br>
CommandText={3}<br>
Parameters={4}<br>", oDetail.UserID, oDetail.UserType, oDetail.EditorID, oDetail.CommandText, oDetail.ParameterDetails);

                    ExceptionManager.Publish(Detail);
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
        }