Skip to content

Commit ba69936

Browse files
committed
Add logging for /waitForDebugger parameter in host
1 parent 11838b0 commit ba69936

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

src/PowerShellEditorServices.Host/Program.cs

+37-23
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,6 @@ class Program
1717
[STAThread]
1818
static void Main(string[] args)
1919
{
20-
#if DEBUG
21-
// In the future, a more robust argument parser will be added here
22-
bool waitForDebugger =
23-
args.Any(
24-
arg =>
25-
string.Equals(
26-
arg,
27-
"/waitForDebugger",
28-
StringComparison.InvariantCultureIgnoreCase));
29-
30-
// Should we wait for the debugger before starting?
31-
if (waitForDebugger)
32-
{
33-
// Wait for 15 seconds and then continue
34-
int waitCountdown = 15;
35-
while (!Debugger.IsAttached && waitCountdown > 0)
36-
{
37-
Thread.Sleep(1000);
38-
waitCountdown--;
39-
}
40-
}
41-
#endif
42-
4320
string logPath = null;
4421
string logPathArgument =
4522
args.FirstOrDefault(
@@ -80,6 +57,43 @@ static void Main(string[] args)
8057
// TODO: Set the level based on command line parameter
8158
Logger.Initialize(logPath, LogLevel.Verbose);
8259

60+
#if DEBUG
61+
bool waitForDebugger =
62+
args.Any(
63+
arg =>
64+
string.Equals(
65+
arg,
66+
"/waitForDebugger",
67+
StringComparison.InvariantCultureIgnoreCase));
68+
69+
// Should we wait for the debugger before starting?
70+
if (waitForDebugger)
71+
{
72+
Logger.Write(LogLevel.Normal, "Waiting for debugger to attach before continuing...");
73+
74+
// Wait for 15 seconds and then continue
75+
int waitCountdown = 15;
76+
while (!Debugger.IsAttached && waitCountdown > 0)
77+
{
78+
Thread.Sleep(1000);
79+
waitCountdown--;
80+
}
81+
82+
if (Debugger.IsAttached)
83+
{
84+
Logger.Write(
85+
LogLevel.Normal,
86+
"Debugger attached, continuing startup sequence");
87+
}
88+
else if (waitCountdown == 0)
89+
{
90+
Logger.Write(
91+
LogLevel.Normal,
92+
"Timed out while waiting for debugger to attach, continuing startup sequence");
93+
}
94+
}
95+
#endif
96+
8397
Logger.Write(LogLevel.Normal, "PowerShell Editor Services Host starting...");
8498

8599
// Start the server

0 commit comments

Comments
 (0)