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

View File

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

View File

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

View File

@@ -27,13 +27,13 @@ Push-Location $repoRoot
try { try {
if (-not $SkipDotnetRestore) { if (-not $SkipDotnetRestore) {
Invoke-Step -Name "Restore .NET solution" -Action { Invoke-Step -Name "Restore .NET solution" -Action {
dotnet restore RpgRoller.sln dotnet restore RpgRoller.sln --verbosity minimal
} }
} }
if (-not $SkipBuild) { if (-not $SkipBuild) {
Invoke-Step -Name "Build .NET solution (warnings as errors)" -Action { 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 { Invoke-Step -Name "Run tests" -Action {
if ($SkipBuild) { 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 { 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
} }
} }