-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed as duplicate of#19526
Labels
Description
File a bug
I have a virtual scrolling listbox, where items are loaded from DB on demand.
As user scrolls, the previous requests are cancelled using CancellationToken, that is passed to IQueryable.ToArrayAsync(), resp CountAsync(); methods
This produces tons of exceptions being logged using ILogger:
fail: Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of a query for context type 'Domain.Manufacture.ManufactureDbContext'.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
I think it should not log the exception with LogLever=Error, as this is expected exception
This is bloats my logs with useful messages. I believe that expected exception should not be logger as Errors.
Would you consider changing LogLevel to Info, or Debug?
Include your code
private async ValueTask<ItemsProviderResult<Employee>> LoadEmployees(
ItemsProviderRequest request)
{
using var dbContext = DbContextFactory.CreateDbContext();
var query = dbContext.MaterialsView.AsNoTracking()
.OrderBy(e => e.Id);
try {
var items = await query.Skip(request.StartIndex).Take(request.Count)
.ToArrayAsync(request.CancellationToken);
var count = await query.CountAsync(request.CancellationToken);
return new ItemsProviderResult<Employee>(items, count);
}
catch (TaskCanceledException) {
// Don't log
return default;
}
}Include provider and version information
EF Core version: 6.0
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 6.0)
Operating system:
IDE: (e.g. Visual Studio 2022 17.0)
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100\
Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa