예제 #1
0
        /// <summary>
        /// Returns a page of errors from the database in descending order
        /// of logged time.
        /// </summary>

        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }
            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            // Skip is not allowed, so we will take extra records and then discard ones that weren't requested.
            // This obviously has a performance hit, but since users are usually looking at the latest ones, this may be OK for most scenarios.
            var partitionKey = AzureHelper.EncodeAzureKey(ApplicationName);
            var tableQuery   = _cloudTable.CreateQuery <ElmahEntity>()
                               .Where(e => e.PartitionKey == partitionKey)
                               .Take((pageIndex + 1) * pageSize);

            var errorEntities = _cloudTable
                                .ExecuteQuery(tableQuery as TableQuery <ElmahEntity>)
                                .Skip(pageIndex * pageSize);

            foreach (var errorEntity in errorEntities)
            {
                var error = ErrorXml.DecodeString(errorEntity.AllXml);
                errorEntryList.Add(new ErrorLogEntry(this, errorEntity.RowKey, error));
            }

            // Azure Table Storage cannot return the total number of records,
            // so if the max number of errors are displayed,
            // we will report an extra element to indicate to the user that more records may exist
            return(errorEntryList.Count == pageSize
                ? (pageIndex + 1) * pageSize + 1
                : pageIndex *pageSize + errorEntryList.Count);
        }
        /// <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");
            }

            var partitionKey = AzureHelper.EncodeAzureKey(ApplicationName);

            var elmahEntity = _cloudTable.CreateQuery <ElmahEntity>()
                              .Where(e => e.PartitionKey == partitionKey && e.RowKey == id)
                              .ToList()
                              .First();

            var error = ErrorXml.DecodeString(elmahEntity.AllXml);

            return(new ErrorLogEntry(this, id, error));
        }
예제 #3
0
 public ElmahEntity(string applicationName)
     : base(AzureHelper.EncodeAzureKey(applicationName), (DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks).ToString("d19"))
 {
 }