示例#1
0
        public BaseResultInfo InsertLogItem(LogItem item)
        {
            BaseResultInfo result = new BaseResultInfo();

            SqlParameterList commandParams = SqlSerializer.Serialize(item);


            try
            {
                using (SqlConnection conn = new SqlConnection(base.ConnectionString))
                {
                    conn.Open();
                    SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, SQL_ADD_LOG_ITEM, commandParams.ToArray());
                    result.ReturnValue = commandParams.GetReturnValue();

                    if (result.ReturnValue < 0)
                    {
                        throw new Exception("SQL_ADD_LOG_ITEM");
                    }
                }
            }
            catch (Exception ex)
            {
                if (result.Error == null)
                {
                    result.Error = new BaseErrorInfo();
                }

                result.Error.BuildException(ex);
            }
            return(result);
        }
示例#2
0
        public BaseResultInfo InsertLogItem(List <LogItem> items)
        {
            SiteLogger.ILogger logger = SiteLogger.LoggingFactory.GetLogger;
            BaseResultInfo     result = new BaseResultInfo();

            List <ResultLogItem> errorData = new List <ResultLogItem>();

            try
            {
                using (SqlConnection conn = new SqlConnection(base.ConnectionString))
                {
                    conn.Open();
                    SqlParameterList commandParams = new SqlParameterList();
                    int successCount = 0;
                    foreach (var item in items)
                    {
                        try
                        {
                            commandParams = SqlSerializer.Serialize(item);
                            int res = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, SQL_ADD_LOG_ITEM, commandParams.ToArray());
                            successCount++;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(string.Format("INDEX = {0}, DATETIME = {1}, LOG_TYPE = {2}, MESSAGE = {3}", item.Index, item.InsertDate, item.LogType, ex.Message));
                            errorData.Add(new ResultLogItem()
                            {
                                Log = item, ErrorMessage = ex.Message
                            });
                        }
                    }
                    result.ReturnValue  = successCount; commandParams.GetReturnValue();
                    result.ResultObject = errorData;
                    conn.Close();
                    if (result.ReturnValue < 0)
                    {
                        throw new Exception("SQL_ADD_LOG_ITEM");
                    }
                }
            }
            catch (Exception ex)
            {
                if (result.Error == null)
                {
                    result.Error = new BaseErrorInfo();
                }

                result.Error.BuildException(ex);
            }
            return(result);
        }