المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : log4net doesn't log in myProcess.OutputDataReceived



C# Programming
08-14-2009, 03:56 PM
Hi,

my app logs correctly while code is beeing executed within my method DoIt. But it doesn't log in the Process.OutputDataReceived's EventHandler even if p_OutputDataReceived is called.

Is there anything I need to look at while using Process?


private void DoIt(string arguments)
{
_log.Fatal("TEST"); // DOES LOG
Process p = new Process();
p.StartInfo.FileName = @"D:\vssTOOLS\NetJobs\UpdateDealArchiveInstrSeq\UpdateCaller\bin\Debug\UpdateDealArchiveInstrSeq.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Caller)).********);
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = arguments;
p.Start();

p.BeginOutputReadLine();
p.BeginErrorReadLine();

p.WaitForExit();

//Synchronisieren
do
{
System.Threading.Thread.Sleep(100);
} while (!p.HasExited);

if (p.ExitCode != 0)
{
// DOES LOG
for (int i = 0; i < procOut.ToString().Length; i += 2000)
_log.Info(procOut.ToString().Length > i + 2000 ? procOut.ToString().Substring(i, 2000) : procOut.ToString().Substring(i));
for (int i = 0; i < procErr.ToString().Length; i += 2000)
_log.Error(procErr.ToString().Length > i + 2000 ? procErr.ToString().Substring(i, 2000) : procErr.ToString().Substring(i));
throw new ApplicationException("Es ist ein Fehler aufgetreten: " + procErr.ToString());
}
}

StringBuilder procOut = new StringBuilder();
StringBuilder procErr = new StringBuilder();
void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
procErr.AppendLine(e.Data);
_log.Error(e.Data); // DOES NOT LOG
}

void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
procOut.AppendLine(e.Data);
_log.Info(e.Data); // DOES NOT LOG
}