Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Shared/LoggingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public static void WriteDashboardSummary(ILogger logger, string? dashboardUrl, s
? $"{dashboardAuthority}/login?t={token}"
: null;

if (loginUrl is not null)
{
// dotnet watch looks for this exact log message to launch the dashboard. Do not change it.
logger.LogInformation("Login to the dashboard at {LoginUrl}", loginUrl);
}

var templateBuilder = new StringBuilder();
var parameters = new List<object?>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ public async Task LogOutput_NoToken_GeneratedTokenLogged()
Assert.Equal(LogLevel.Warning, w.LogLevel);
},
w =>
{
Assert.Equal("Login to the dashboard at {LoginUrl}", LogTestHelpers.GetValue(w, "{OriginalFormat}"));

var loginUrl = (string)LogTestHelpers.GetValue(w, "LoginUrl")!;
var uri = new Uri(loginUrl, UriKind.Absolute);
var queryString = HttpUtility.ParseQueryString(uri.Query);
Assert.NotNull(queryString["t"]);
},
w =>
{
Assert.StartsWith("Aspire Dashboard", (string)LogTestHelpers.GetValue(w, "{OriginalFormat}")!);

Expand Down
19 changes: 15 additions & 4 deletions tests/Aspire.Dashboard.Tests/LoggingHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ public void WriteDashboardSummary_WithTokenAndOtlpEndpoints_LogsSummaryAndStruct
"http://localhost:18890",
"abc123");

var write = Assert.Single(sink.Writes);
Assert.Equal(2, sink.Writes.Count);

var loginWrite = sink.Writes.ElementAt(0);
Assert.Equal(LogLevel.Information, loginWrite.LogLevel);
Assert.Equal("Login to the dashboard at http://localhost:18888/login?t=abc123", loginWrite.Message);
Assert.Equal("Login to the dashboard at {LoginUrl}", LogTestHelpers.GetValue(loginWrite, "{OriginalFormat}"));
Assert.Equal("http://localhost:18888/login?t=abc123", LogTestHelpers.GetValue(loginWrite, "LoginUrl"));

var write = sink.Writes.ElementAt(1);
Assert.Equal(LogLevel.Information, write.LogLevel);
Assert.NotNull(write.Message);
var lines = GetMessageLines(write.Message!);
Expand Down Expand Up @@ -169,7 +177,9 @@ public void WriteDashboardSummary_WithoutOtlpEndpoints_DoesNotIncludeOtlpLines()
otlpHttpUrl: null,
token: "abc123");

var write = Assert.Single(sink.Writes);
Assert.Equal(2, sink.Writes.Count);

var write = sink.Writes.ElementAt(1);
Assert.NotNull(write.Message);
var lines = GetMessageLines(write.Message!);

Expand Down Expand Up @@ -198,8 +208,9 @@ public void WriteDashboardSummary_IsContainer_IncludesContainerMessage()
token: "abc123",
isContainer: true);

Assert.Equal(2, sink.Writes.Count);
var containerWrite = sink.Writes.Skip(1).First();
Assert.Equal(3, sink.Writes.Count);

var containerWrite = sink.Writes.ElementAt(2);
Assert.Equal("Dashboard is running in a container. Access the dashboard from the host using port forwarding.", containerWrite.Message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ public async Task ResourceReadyEvent_LogsDashboardUrlFromAllocatedEndpoint(strin
Assert.Equal(allocatedPort, uri.Port);
Assert.Equal(expectedScheme, uri.Scheme);

var loginLog = testSink.Writes.FirstOrDefault(l =>
LogTestHelpers.GetValue(l, "{OriginalFormat}")?.ToString() == "Login to the dashboard at {LoginUrl}");

Assert.NotNull(loginLog);
Assert.Equal($"{expectedScheme}://{expectedHost}:{allocatedPort}/login?t=test-token", LogTestHelpers.GetValue(loginLog, "LoginUrl"));

var summaryLog = testSink.Writes.FirstOrDefault(l =>
LogTestHelpers.GetValue(l, "{OriginalFormat}")?.ToString()?.Contains("OTLP/gRPC:") == true);

Expand Down
Loading