Skip to content
代码片段 群组 项目
未验证 提交 a32d3be7 编辑于 作者: github-actions[bot]'s avatar github-actions[bot] 提交者: GitHub
浏览文件

Don't log status messages for debug proxy. Fixes #35292 (#36223)

上级 12bba858
No related branches found
No related tags found
无相关合并请求
...@@ -23,6 +23,13 @@ namespace Microsoft.AspNetCore.Builder ...@@ -23,6 +23,13 @@ namespace Microsoft.AspNetCore.Builder
private static Task<string>? LaunchedDebugProxyUrl; private static Task<string>? LaunchedDebugProxyUrl;
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$", RegexOptions.None, TimeSpan.FromSeconds(10)); private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$", RegexOptions.None, TimeSpan.FromSeconds(10));
private static readonly Regex ApplicationStartedRegex = new Regex(@"^\s*Application started\. Press Ctrl\+C to shut down\.$", RegexOptions.None, TimeSpan.FromSeconds(10)); private static readonly Regex ApplicationStartedRegex = new Regex(@"^\s*Application started\. Press Ctrl\+C to shut down\.$", RegexOptions.None, TimeSpan.FromSeconds(10));
private static readonly string[] MessageSuppressionPrefixes = new[]
{
"Hosting environment:",
"Content root path:",
"Now listening on:",
"Application started. Press Ctrl+C to shut down.",
};
public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider, string devToolsHost) public static Task<string> EnsureLaunchedAndGetUrl(IServiceProvider serviceProvider, string devToolsHost)
{ {
...@@ -110,6 +117,24 @@ namespace Microsoft.AspNetCore.Builder ...@@ -110,6 +117,24 @@ namespace Microsoft.AspNetCore.Builder
{ {
process.OutputDataReceived += (sender, eventArgs) => process.OutputDataReceived += (sender, eventArgs) =>
{ {
// It's confusing if the debug proxy emits its own startup status messages, because the developer
// may think the ports/environment/paths refer to their actual application. So we want to suppress
// them, but we can't stop the debug proxy app from emitting the messages entirely (e.g., via
// SuppressStatusMessages) because we need the "Now listening on" one to detect the chosen port.
// Instead, we'll filter out known strings from the passthrough logic. It's legit to hardcode these
// strings because they are also hardcoded like this inside WebHostExtensions.cs and can't vary
// according to culture.
if (eventArgs.Data is not null)
{
foreach (var prefix in MessageSuppressionPrefixes)
{
if (eventArgs.Data.StartsWith(prefix, StringComparison.Ordinal))
{
return;
}
}
}
Console.WriteLine(eventArgs.Data); Console.WriteLine(eventArgs.Data);
}; };
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册