Updated diagnostic summary logger to have more sensible category/source name

This commit is contained in:
Brett Hazen 2025-06-12 11:37:33 -05:00
parent 24758ff193
commit 80fdcbb8be
2 changed files with 10 additions and 9 deletions

View file

@ -9,8 +9,9 @@ using Microsoft.Extensions.Logging;
namespace Duende.IdentityServer.Licensing.V2.Diagnostics;
internal class DiagnosticSummary(IEnumerable<IDiagnosticEntry> entries, IdentityServerOptions options, ILogger<DiagnosticSummary> logger)
internal class DiagnosticSummary(IEnumerable<IDiagnosticEntry> entries, IdentityServerOptions options, ILoggerFactory loggerFactory)
{
private readonly ILogger _logger = loggerFactory.CreateLogger("Duende.IdentityServer.Diagnostics.Summary");
public async Task PrintSummary()
{
var bufferWriter = new ArrayBufferWriter<byte>();
@ -39,12 +40,12 @@ internal class DiagnosticSummary(IEnumerable<IDiagnosticEntry> entries, Identity
var offset = i * chunkSize;
var length = Math.Min(chunkSize, span.Length - offset);
var chunk = span.Slice(offset, length);
logger.DiagnosticSummaryLogged(i + 1, totalChunks, Encoding.UTF8.GetString(chunk));
_logger.DiagnosticSummaryLogged(i + 1, totalChunks, Encoding.UTF8.GetString(chunk));
}
}
else
{
logger.DiagnosticSummaryLogged(1, 1, Encoding.UTF8.GetString(bufferWriter.WrittenSpan));
_logger.DiagnosticSummaryLogged(1, 1, Encoding.UTF8.GetString(bufferWriter.WrittenSpan));
}
}
}

View file

@ -15,7 +15,7 @@ public class DiagnosticSummaryTests
[Fact]
public async Task PrintSummary_ShouldCallWriteAsyncOnEveryDiagnosticEntry()
{
var fakeLogger = new NullLogger<DiagnosticSummary>();
var logger = new NullLogger<DiagnosticSummary>();
var firstDiagnosticEntry = new TestDiagnosticEntry();
var secondDiagnosticEntry = new TestDiagnosticEntry();
var thirdDiagnosticEntry = new TestDiagnosticEntry();
@ -25,7 +25,7 @@ public class DiagnosticSummaryTests
secondDiagnosticEntry,
thirdDiagnosticEntry
};
var summary = new DiagnosticSummary(entries, new IdentityServerOptions(), fakeLogger);
var summary = new DiagnosticSummary(entries, new IdentityServerOptions(), new StubLoggerFactory(logger));
await summary.PrintSummary();
@ -42,7 +42,7 @@ public class DiagnosticSummaryTests
var logger = new FakeLogger<DiagnosticSummary>();
var diagnosticEntry = new LongDiagnosticEntry { OutputLength = chunkSize * 2 };
var summary = new DiagnosticSummary([diagnosticEntry], options, logger);
var summary = new DiagnosticSummary([diagnosticEntry], options, new StubLoggerFactory(logger));
await summary.PrintSummary();
@ -61,7 +61,7 @@ public class DiagnosticSummaryTests
var logger = new FakeLogger<DiagnosticSummary>();
var diagnosticEntry = new LongDiagnosticEntry { OutputLength = 2, OutputCharacter = '€' };
var summary = new DiagnosticSummary([diagnosticEntry], options, logger);
var summary = new DiagnosticSummary([diagnosticEntry], options, new StubLoggerFactory(logger));
await summary.PrintSummary();
@ -76,7 +76,7 @@ public class DiagnosticSummaryTests
var logger = new FakeLogger<DiagnosticSummary>();
var diagnosticEntry = new LongDiagnosticEntry { OutputLength = options.Diagnostics.ChunkSize * 2 };
var summary = new DiagnosticSummary([diagnosticEntry], options, logger);
var summary = new DiagnosticSummary([diagnosticEntry], options, new StubLoggerFactory(logger));
await summary.PrintSummary();
foreach (var entry in logger.Collector.GetSnapshot())
@ -91,7 +91,7 @@ public class DiagnosticSummaryTests
var options = new IdentityServerOptions();
var logger = new FakeLogger<DiagnosticSummary>();
var diagnosticEntry = new LongDiagnosticEntry { OutputLength = 100000 };
var summary = new DiagnosticSummary([diagnosticEntry], options, logger);
var summary = new DiagnosticSummary([diagnosticEntry], options, new StubLoggerFactory(logger));
await summary.PrintSummary();