Example #1
0
        /// <summary>
        /// Returns the specified error from the database, or null
        /// if it does not exist.
        /// </summary>

        public override ErrorLogEntry GetError(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            if (id.Length == 0)
            {
                throw new ArgumentException(null, "id");
            }

            Guid errorGuid;

            try
            {
                errorGuid = new Guid(id);
            }
            catch (FormatException e)
            {
                throw new ArgumentException(e.Message, "id", e);
            }

            string errorXml;

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
                using (SqlCommand command = Commands.GetErrorXml(this.ApplicationName, errorGuid))
                {
                    command.Connection = connection;
                    connection.Open();
                    errorXml = (string)command.ExecuteScalar();
                }

            if (errorXml == null)
            {
                return(null);
            }

            Error error = ErrorXml.DecodeString(errorXml);

            return(new ErrorLogEntry(this, id, error));
        }
Example #2
0
        /// <summary>
        /// Returns the specified error from the database, or null
        /// if it does not exist.
        /// </summary>
        public override ErrorLogEntry GetError(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Length == 0)
            {
                throw new ArgumentException(null, "id");
            }
            string errorXml    = string.Empty;
            var    connections = new List <string>();

            if (this.ConnectionString.Contains(","))
            {
                foreach (var connection in this.ConnectionString.Split(','))
                {
                    connections.Add(connection);
                }
            }
            var redisManager = connections.Count() == 0 ? new RedisManagerPool(this.ConnectionString) : new RedisManagerPool(connections);

            using (var client = redisManager.GetClient())
            {
                Guid errorGuid   = new Guid(id);
                var  redis       = client.As <RedisObject>();
                var  redisObject = redis.GetById(errorGuid);
                if (redisObject != null)
                {
                    errorXml = redisObject.AllXml;
                }
            }
            if (errorXml == null)
            {
                return(null);
            }

            Error error = ErrorXml.DecodeString(errorXml);

            return(new ErrorLogEntry(this, id, error));
        }
Example #3
0
        /// <summary>
        /// Returns a page of errors from the databse in descending order
        /// of logged time.
        /// </summary>
        public override int GetErrors(int pageIndex, int pageSize, ICollection <ErrorLogEntry> errorEntryList)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }
            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }
            var connections = new List <string>();

            if (this.ConnectionString.Contains(","))
            {
                foreach (var connection in this.ConnectionString.Split(','))
                {
                    connections.Add(connection);
                }
            }
            var redisManager = connections.Count() == 0 ? new RedisManagerPool(this.ConnectionString) : new RedisManagerPool(connections);

            using (var client = redisManager.GetClient())
            {
                var redis   = client.As <RedisObject>();
                var index   = pageIndex - 1;
                var objects = redis.GetLatestFromRecentsList(1, pageSize);
                foreach (var redisError in objects)
                {
                    errorEntryList.Add(new ErrorLogEntry(this, redisError.ErrorId.ToString(), ErrorXml.DecodeString(redisError.AllXml)));
                }
                var total = client.As <RedisObject>().GetAll().Count();
                return(total);
            }
        }