diff --git a/osu.Server.Spectator.Tests/ScoreUploaderTests.cs b/osu.Server.Spectator.Tests/ScoreUploaderTests.cs index 41d9d9cf..78ca9d54 100644 --- a/osu.Server.Spectator.Tests/ScoreUploaderTests.cs +++ b/osu.Server.Spectator.Tests/ScoreUploaderTests.cs @@ -4,6 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Moq; using osu.Game.Online.API.Requests.Responses; using osu.Game.Scoring; @@ -33,8 +34,12 @@ public ScoreUploaderTests() var databaseFactory = new Mock(); databaseFactory.Setup(factory => factory.GetInstance()).Returns(mockDatabase.Object); + var loggerFactory = new Mock(); + loggerFactory.Setup(factory => factory.CreateLogger(It.IsAny())) + .Returns(new Mock().Object); + mockStorage = new Mock(); - uploader = new ScoreUploader(databaseFactory.Object, mockStorage.Object); + uploader = new ScoreUploader(loggerFactory.Object, databaseFactory.Object, mockStorage.Object); uploader.UploadInterval = 1000; // Set a high timer interval for testing purposes. } diff --git a/osu.Server.Spectator.Tests/SpectatorHubTest.cs b/osu.Server.Spectator.Tests/SpectatorHubTest.cs index 0a971222..79ae7285 100644 --- a/osu.Server.Spectator.Tests/SpectatorHubTest.cs +++ b/osu.Server.Spectator.Tests/SpectatorHubTest.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Moq; using osu.Game.Beatmaps; @@ -61,8 +62,12 @@ public SpectatorHubTest() var databaseFactory = new Mock(); databaseFactory.Setup(factory => factory.GetInstance()).Returns(mockDatabase.Object); + var loggerFactory = new Mock(); + loggerFactory.Setup(factory => factory.CreateLogger(It.IsAny())) + .Returns(new Mock().Object); + mockScoreStorage = new Mock(); - scoreUploader = new ScoreUploader(databaseFactory.Object, mockScoreStorage.Object); + scoreUploader = new ScoreUploader(loggerFactory.Object, databaseFactory.Object, mockScoreStorage.Object); var mockScoreProcessedSubscriber = new Mock(); diff --git a/osu.Server.Spectator/Hubs/ScoreUploader.cs b/osu.Server.Spectator/Hubs/ScoreUploader.cs index adf219a2..5a4d93df 100644 --- a/osu.Server.Spectator/Hubs/ScoreUploader.cs +++ b/osu.Server.Spectator/Hubs/ScoreUploader.cs @@ -5,6 +5,7 @@ using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using osu.Game.Scoring; using osu.Server.Spectator.Database; using osu.Server.Spectator.Database.Models; @@ -31,11 +32,16 @@ public class ScoreUploader : IEntityStore, IDisposable private readonly IScoreStorage scoreStorage; private readonly CancellationTokenSource cancellationSource; private readonly CancellationToken cancellationToken; + private readonly ILogger logger; - public ScoreUploader(IDatabaseFactory databaseFactory, IScoreStorage scoreStorage) + public ScoreUploader( + ILoggerFactory loggerFactory, + IDatabaseFactory databaseFactory, + IScoreStorage scoreStorage) { this.databaseFactory = databaseFactory; this.scoreStorage = scoreStorage; + logger = loggerFactory.CreateLogger(nameof(ScoreUploader)); cancellationSource = new CancellationTokenSource(); cancellationToken = cancellationSource.Token; @@ -104,7 +110,7 @@ public async Task Flush() { if (dbScore == null) { - Console.WriteLine($"Score upload timed out for token: {item.Token}"); + logger.LogError("Score upload timed out for token: {tokenId}", item.Token); return; } @@ -127,7 +133,7 @@ public async Task Flush() } catch (Exception e) { - Console.WriteLine($"Error during score upload: {e}"); + logger.LogError(e, "Error during score upload"); } } diff --git a/osu.Server.Spectator/Startup.cs b/osu.Server.Spectator/Startup.cs index 1e19f063..b72c1ab5 100644 --- a/osu.Server.Spectator/Startup.cs +++ b/osu.Server.Spectator/Startup.cs @@ -67,6 +67,7 @@ public void ConfigureServices(IServiceCollection services) logging.ClearProviders(); logging.AddConsole(); + logging.AddSentry(); // IdentityModelEventSource.ShowPII = true; });