Describe the bug
Bug is that logs aren't ordered in serilog-ui with a Mongo database.
To Reproduce
Steps to reproduce the behavior:
Use Serilog.UI and Serilog.UI.MongoDbProvider nuggets.
Open the serilog-ui page
You'll see your logs not ordered by date.
Expected behavior
Logs order by DESC date when using a mongo db.
Screenshots
The form is not filtered.
I've precise what are suppose to be the good order.
1 and 4 has to be 8 and 9 even if it's same date, i've check in database milliseconds.
Desktop :
OS: Windows 11
Browser Chrome and Firefox (last versions)
Version net6.0 and net8.0
Additional context
Following this: https://github.com/serilog-contrib/serilog-ui/pull/34 where TimeStamp has been change to UtcTimeStamp.
I think there is still a problem in MongoDbDataProvider > GetLogsAsync() because code is still using TimeStamp to do the SortByDescending.
private async Task<IEnumerable<LogModel>> GetLogsAsync(
int page,
int count,
string level,
string searchCriteria,
DateTime? startDate,
DateTime? endDate)
{
try
{
var builder = Builders<MongoDbLogModel>.Filter.Empty;
GenerateWhereClause(ref builder, level, searchCriteria, startDate, endDate);
if (!string.IsNullOrWhiteSpace(searchCriteria))
{
await _collection.Indexes.CreateOneAsync(
new CreateIndexModel<MongoDbLogModel>(Builders<MongoDbLogModel>.IndexKeys.Text(p => p.RenderedMessage)));
}
var logs = await _collection
.Find(builder)
.Skip(count * page)
.Limit(count)
.SortByDescending(entry => entry.Timestamp)
.ToListAsync();
var index = 1;
foreach (var log in logs)
log.Id = (page * count) + index++;
return logs.Select(log => log.ToLogModel()).ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
I've also check code in feature/3.0 branch, sort is also done with TimeStamp.
Describe the bug Bug is that logs aren't ordered in serilog-ui with a Mongo database.
To Reproduce Steps to reproduce the behavior:
Expected behavior Logs order by DESC date when using a mongo db.
Screenshots The form is not filtered. I've precise what are suppose to be the good order. 1 and 4 has to be 8 and 9 even if it's same date, i've check in database milliseconds.
Desktop :
Additional context Following this: https://github.com/serilog-contrib/serilog-ui/pull/34 where TimeStamp has been change to UtcTimeStamp. I think there is still a problem in MongoDbDataProvider > GetLogsAsync() because code is still using TimeStamp to do the SortByDescending.
I've also check code in feature/3.0 branch, sort is also done with TimeStamp.