Skip to content

Commit

Permalink
Add logging to NewsArticleProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Aug 22, 2023
1 parent 741d961 commit 7413919
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/server/web/News/NewsArticleProvider.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
namespace Arise.Server.Web.News;

public sealed class NewsArticleProvider : IHostedService
public sealed partial class NewsArticleProvider : IHostedService
{
private static partial class Log
{
[LoggerMessage(0, LogLevel.Information, "Loaded {Count} news articles in {ElapsedMs:0.0000} ms")]
public static partial void LoadedNewsArticles(ILogger logger, int count, double elapsedMs);
}

public IEnumerable<NewsArticle> Articles { get; private set; } = null!;

private readonly IHostEnvironment _environment;

public NewsArticleProvider(IHostEnvironment environment)
private readonly ILogger<NewsArticleProvider> _logger;

public NewsArticleProvider(IHostEnvironment environment, ILogger<NewsArticleProvider> logger)
{
_environment = environment;
_logger = logger;
}

[RegisterServices]
Expand All @@ -19,6 +28,8 @@ internal static void Register(IServiceCollection services)

public async Task StartAsync(CancellationToken cancellationToken)
{
var stamp = Stopwatch.GetTimestamp();

var provider = _environment.ContentRootFileProvider;

IEnumerable<IFileInfo> GetContents(params string[] names)
Expand Down Expand Up @@ -90,6 +101,8 @@ from articleFile in GetContents(year, month, day)
.OrderByDescending(static article => article.Date)
.ThenBy(static article => article.Slug)
.ToArray();

Log.LoadedNewsArticles(_logger, articles.Count, Stopwatch.GetElapsedTime(stamp).TotalMilliseconds);
}

public Task StopAsync(CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions src/server/world/Bridge/BridgeModuleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed partial class BridgeModuleProvider : BackgroundService
private static partial class Log
{
[LoggerMessage(0, LogLevel.Information, "Generated {Count} bridge modules in {ElapsedMs:0.0000} ms")]
public static partial void GeneratedModules(
public static partial void GeneratedBridgeModules(
Microsoft.Extensions.Logging.ILogger logger, int count, double elapsedMs);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ ReadOnlyMemory<byte> CreateModule(BridgeModuleKind kind, int seed)
}
}

Log.GeneratedModules(
Log.GeneratedBridgeModules(
_logger, _options.Value.ConcurrentModules, Stopwatch.GetElapsedTime(stamp).TotalMilliseconds);

await Task.Delay(_options.Value.ModuleRotationTime.ToTimeSpan(), stoppingToken);
Expand Down
3 changes: 2 additions & 1 deletion src/server/world/Data/DataGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ internal static void Register(IServiceCollection services)

public async Task StartAsync(CancellationToken cancellationToken)
{
var stamp = Stopwatch.GetTimestamp();

await using var stream = EmbeddedDataCenter.OpenStream();

var mode = _environment.IsDevelopment() ? DataCenterLoaderMode.Lazy : DataCenterLoaderMode.Eager;
var stamp = Stopwatch.GetTimestamp();

Root = await DataCenter.LoadAsync(
stream,
Expand Down

0 comments on commit 7413919

Please sign in to comment.