How to silent BackgroundJobsDbContext logging?
It is useful since ABP 3.1 that Serilog writes to console.
But AbpBackgroundJobs is really spamming.
[14:56:59 INF] Entity Framework Core 3.1.6 initialized 'BackgroundJobsDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
[14:56:59 INF] Executed DbCommand (6ms) [Parameters=[@__p_1='?' (DbType = Int32), @__now_0='?' (DbType = DateTime2)], CommandType='Text', CommandTimeout='30']
SELECT TOP(@__p_1) [a].[Id], [a].[ConcurrencyStamp], [a].[CreationTime], [a].[ExtraProperties], [a].[IsAbandoned], [a].[JobArgs], [a].[JobName], [a].[LastTryTime], [a].[NextTryTime], [a].[Priority], [a].[TryCount]
FROM [AbpBackgroundJobs] AS [a]
WHERE ([a].[IsAbandoned] <> CAST(1 AS bit)) AND ([a].[NextTryTime] <= @__now_0)
ORDER BY [a].[Priority] DESC, [a].[TryCount], [a].[NextTryTime]
[14:57:04 INF] Entity Framework Core 3.1.6 initialized 'BackgroundJobsDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
[14:57:04 INF] Executed DbCommand ...
...
How to keep logging to console but filtering out BackgroundJobs queries?
hi
You can refer to the Microsoft's document.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#log-level
Thank you @maliming but your link points to a section describing log level filtering. Again, I am interested by nearly all the current Serilog logging (especially for spying my queries) but I only want to silent out BackgroundJobs queries. If I tell Serilog to silent out Information level, I am afraid that all the queries will be missing.
hi
You can search it in asp net core or ef core. ABP is just using the it to write the log.
https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging?tabs=v3#filtering-what-is-logged
@Stirda I've had good results by adding the following lines to the API Host project's Program.cs, right after .MinimumLevel.Override:
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Infrastructure", LogEventLevel.Warning)
You can use Serilog's filter expressions feature to filter out the BackgroundJobs stuff (add the NuGet Serilog.Filters.Expressions package to your project first):
.Filter.ByExcluding("SourceContext = 'Microsoft.EntityFrameworkCore.Database.Command' and @Message like '%BackgroundJob%'") .Filter.ByExcluding("SourceContext = 'Microsoft.EntityFrameworkCore.Infrastructure' and @Message like '%BackgroundJob%'")
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.