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);
const string sql = @"
SELECT
[ErrorId],
[Application],
[Host],
[Type],
[Source],
[Message],
[User],
[StatusCode],
[TimeUtc]
FROM
[ELMAH_Error]
ORDER BY
[TimeUtc] DESC,
[Sequence] DESC
OFFSET @PageSize * @PageIndex ROWS FETCH NEXT @PageSize ROWS ONLY;
";
const string getCount = @"
SELECT COUNT(*) FROM [ELMAH_Error]";
using (var connection = new SqlCeConnection(ConnectionString))
{
connection.Open();
using (var command = new SqlCeCommand(sql, connection))
{
var parameters = command.Parameters;
parameters.Add("@PageIndex", SqlDbType.Int).Value = pageIndex;
parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize;
parameters.Add("@Application", SqlDbType.NVarChar, 60).Value = ApplicationName;
using (var reader = command.ExecuteReader())
{
if (errorEntryList != null)
{
while (reader.Read())
{
var id = reader["ErrorId"].ToString();
var error = new Elmah.Error();
error.ApplicationName = reader["Application"].ToString();
error.HostName = reader["Host"].ToString();
error.Type = reader["Type"].ToString();
error.Source = reader["Source"].ToString();
error.Message = reader["Message"].ToString();
error.User = reader["User"].ToString();
error.StatusCode = Convert.ToInt32(reader["StatusCode"]);
error.Time = Convert.ToDateTime(reader["TimeUtc"]).ToLocalTime();
errorEntryList.Add(new ErrorLogEntry(this, id, error));
}
}
}
}
using (var command = new SqlCeCommand(getCount, connection))
{
return (int)command.ExecuteScalar();
}
}
}