Redirecting output for all process starts to see correlation in logs.

This commit is contained in:
Praburaj 2015-04-20 16:19:56 -07:00
parent f3a4cf0ea7
commit f92b1f36e1
3 changed files with 22 additions and 8 deletions

View File

@ -86,10 +86,17 @@ namespace Microsoft.AspNet.Server.Testing
FileName = dnuPath, FileName = dnuPath,
Arguments = parameters, Arguments = parameters,
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = false CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true
}; };
var hostProcess = Process.Start(startInfo); var hostProcess = new Process() { StartInfo = startInfo };
hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); };
hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); };
hostProcess.Start();
hostProcess.BeginErrorReadLine();
hostProcess.BeginOutputReadLine();
hostProcess.WaitForExit(); hostProcess.WaitForExit();
if (hostProcess.ExitCode != 0) if (hostProcess.ExitCode != 0)

View File

@ -90,7 +90,9 @@ namespace Microsoft.AspNet.Server.Testing
FileName = iisExpressPath, FileName = iisExpressPath,
Arguments = parameters, Arguments = parameters,
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = false CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true
}; };
AddEnvironmentVariablesToProcess(startInfo); AddEnvironmentVariablesToProcess(startInfo);
@ -104,13 +106,18 @@ namespace Microsoft.AspNet.Server.Testing
SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath); SetEnvironmentVariable(startInfo.Environment, "DNX_APPBASE", DeploymentParameters.ApplicationPath);
#endif #endif
_hostProcess = Process.Start(startInfo); _hostProcess = new Process() { StartInfo = startInfo };
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); };
_hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); };
_hostProcess.EnableRaisingEvents = true; _hostProcess.EnableRaisingEvents = true;
var hostExitTokenSource = new CancellationTokenSource(); var hostExitTokenSource = new CancellationTokenSource();
_hostProcess.Exited += (sender, e) => _hostProcess.Exited += (sender, e) =>
{ {
TriggerHostShutdown(hostExitTokenSource); TriggerHostShutdown(hostExitTokenSource);
}; };
_hostProcess.Start();
_hostProcess.BeginErrorReadLine();
_hostProcess.BeginOutputReadLine();
if (_hostProcess.HasExited) if (_hostProcess.HasExited)
{ {

View File

@ -58,7 +58,6 @@ namespace Microsoft.AspNet.Server.Testing
FileName = dnxPath, FileName = dnxPath,
Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint), Arguments = string.Format("\"{0}\" {1} --server.urls {2}", DeploymentParameters.ApplicationPath, commandName, DeploymentParameters.ApplicationBaseUriHint),
UseShellExecute = false, UseShellExecute = false,
// https://github.com/aspnet/Hosting/issues/140 causing host process to exit when this is made false.
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardError = true, RedirectStandardError = true,
RedirectStandardOutput = true RedirectStandardOutput = true
@ -66,9 +65,7 @@ namespace Microsoft.AspNet.Server.Testing
AddEnvironmentVariablesToProcess(startInfo); AddEnvironmentVariablesToProcess(startInfo);
_hostProcess = Process.Start(startInfo); _hostProcess = new Process() { StartInfo = startInfo };
_hostProcess.BeginErrorReadLine();
_hostProcess.BeginOutputReadLine();
_hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); }; _hostProcess.ErrorDataReceived += (sender, dataArgs) => { Logger.LogError(dataArgs.Data); };
_hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); }; _hostProcess.OutputDataReceived += (sender, dataArgs) => { Logger.LogInformation(dataArgs.Data); };
_hostProcess.EnableRaisingEvents = true; _hostProcess.EnableRaisingEvents = true;
@ -77,6 +74,9 @@ namespace Microsoft.AspNet.Server.Testing
{ {
TriggerHostShutdown(hostExitTokenSource); TriggerHostShutdown(hostExitTokenSource);
}; };
_hostProcess.Start();
_hostProcess.BeginErrorReadLine();
_hostProcess.BeginOutputReadLine();
if (_hostProcess.HasExited) if (_hostProcess.HasExited)
{ {