'get the complete error message from ErrorDataReceived event
I have written a process monitoring tool that restarts an application in some error scenarios. I also want to catch unhandled .NET errors and this works fine with following code:
ExterneAnwendung = New System.Diagnostics.Process()
ExterneAnwendung.Start()
ProcessName = ExterneAnwendung.ProcessName
AddHandler ExterneAnwendung.ErrorDataReceived, AddressOf ErrorDataHandler
ExterneAnwendung.BeginErrorReadLine()
Private Sub ErrorDataHandler(sendingProcess As Object, errLine As DataReceivedEventArgs)
If Not String.IsNullOrEmpty(errLine.Data) Then
errFromApp = errLine.Data
End If
End Sub
If Not errFromApp Is Nothing Then
Log("Die Anwendung " & ExterneAnwendung.StartInfo.FileName & " hat einen Fehler gemeldet: " + errFromApp)
ExterneAnwendung.CloseMainWindow()
End If
Now it gives me errors like this:
Die Anwendung C:\BEA\NIF\NIF-Funkstelle.exe hat einen Fehler gemeldet: at System.Threading.Thread.StartCallback()
However, the whole stack trace would be much more useful. Its like this:
Application: NIF-Funkstelle.exe CoreCLR Version: 6.0.21.52210 .NET Version: 6.0.0 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.IOException: Unable to write data to the transport connection: Eine bestehende Verbindung wurde softwaregesteuert durch den Hostcomputer abgebrochen.. ---> System.Net.Sockets.SocketException (10053): Eine bestehende Verbindung wurde softwaregesteuert durch den Hostcomputer abgebrochen. at System.Net.Sockets.NetworkStream.Write(ReadOnlySpan
1 buffer) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write(ReadOnlySpan1 buffer) at MizuVOIP.Mizu_TCP_Handler.writeLine(String dataTX) at MizuVOIP.SIPstack.register(Boolean log) at MizuVOIP.SIPstack.controlThread(Object obj) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
Now my final question: Is there any way to get the stack trace with the DataReceivedEventArgs?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
