Mute logspam

This commit is contained in:
2026-04-04 20:33:44 +02:00
parent 22ee512cb7
commit 2e6951e695
4 changed files with 33 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using RpgRoller.Data;
using RpgRoller.Hosting;
@@ -272,6 +273,9 @@ public sealed class HostingCoverageTests
ContentRootPath = Path.GetTempPath(),
EnvironmentName = Environments.Development
});
builder.Logging.AddFilter("Microsoft.AspNetCore", LogLevel.Warning);
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
builder.Logging.AddFilter("Microsoft.Hosting", LogLevel.Warning);
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["ConnectionStrings:RpgRoller"] = $"Data Source={copiedDbPath}"

View File

@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using RpgRoller.Data;
using RpgRoller.Hosting;
@@ -31,20 +33,29 @@ public abstract class ApiTestBase : IClassFixture<WebApplicationFactory<Program>
protected WebApplicationFactory<Program> CreateFactory(params int[] rollValues)
{
return m_BaseFactory.WithWebHostBuilder(builder => builder.ConfigureServices(services =>
return m_BaseFactory.WithWebHostBuilder(builder =>
{
services.RemoveAll<IDiceRoller>();
services.AddSingleton<IDiceRoller>(new FixedDiceRoller(rollValues));
builder.ConfigureLogging(logging =>
{
logging.AddFilter("Microsoft.AspNetCore", LogLevel.Warning);
logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
logging.AddFilter("Microsoft.Hosting", LogLevel.Warning);
});
builder.ConfigureServices(services =>
{
services.RemoveAll<IDiceRoller>();
services.AddSingleton<IDiceRoller>(new FixedDiceRoller(rollValues));
services.RemoveAll<DbContextOptions<RpgRollerDbContext>>();
services.RemoveAll<IDbContextFactory<RpgRollerDbContext>>();
services.RemoveAll<RpgRollerDbContext>();
services.RemoveAll<SqliteDatabaseFile>();
services.RemoveAll<DbContextOptions<RpgRollerDbContext>>();
services.RemoveAll<IDbContextFactory<RpgRollerDbContext>>();
services.RemoveAll<RpgRollerDbContext>();
services.RemoveAll<SqliteDatabaseFile>();
var dbPath = Path.Combine(Path.GetTempPath(), $"rpgroller-tests-{Guid.NewGuid():N}.db");
services.AddSingleton(new SqliteDatabaseFile(dbPath));
services.AddDbContextFactory<RpgRollerDbContext>(options => options.UseSqlite($"Data Source={dbPath}"));
}));
var dbPath = Path.Combine(Path.GetTempPath(), $"rpgroller-tests-{Guid.NewGuid():N}.db");
services.AddSingleton(new SqliteDatabaseFile(dbPath));
services.AddDbContextFactory<RpgRollerDbContext>(options => options.UseSqlite($"Data Source={dbPath}"));
});
});
}
protected static async Task<UserSummary> RegisterAsync(HttpClient client, string username, string password, string displayName)

View File

@@ -5,7 +5,9 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore": "Warning",
"Microsoft.Hosting": "Warning"
}
},
"AllowedHosts": "*"

View File

@@ -27,13 +27,13 @@ Push-Location $repoRoot
try {
if (-not $SkipDotnetRestore) {
Invoke-Step -Name "Restore .NET solution" -Action {
dotnet restore RpgRoller.sln
dotnet restore RpgRoller.sln --verbosity minimal
}
}
if (-not $SkipBuild) {
Invoke-Step -Name "Build .NET solution (warnings as errors)" -Action {
dotnet build RpgRoller.sln --no-restore -warnaserror
dotnet build RpgRoller.sln --no-restore -warnaserror --verbosity minimal
}
}
@@ -47,10 +47,10 @@ try {
Invoke-Step -Name "Run tests" -Action {
if ($SkipBuild) {
dotnet test RpgRoller.Tests/RpgRoller.Tests.csproj --verbosity normal --collect:"XPlat Code Coverage" --settings RpgRoller.Tests/coverlet.runsettings
dotnet test RpgRoller.Tests/RpgRoller.Tests.csproj --verbosity minimal --collect:"XPlat Code Coverage" --settings RpgRoller.Tests/coverlet.runsettings
}
else {
dotnet test RpgRoller.Tests/RpgRoller.Tests.csproj --no-build --verbosity normal --collect:"XPlat Code Coverage" --settings RpgRoller.Tests/coverlet.runsettings
dotnet test RpgRoller.Tests/RpgRoller.Tests.csproj --no-build --verbosity minimal --collect:"XPlat Code Coverage" --settings RpgRoller.Tests/coverlet.runsettings
}
}