Skip to content

Commit

Permalink
all: Do not lose exception stacktraces in logs
Browse files Browse the repository at this point in the history
Hard to debug issues when no stacktrace.
  • Loading branch information
dimhotepus committed Dec 16, 2023
1 parent e3379a7 commit 945933f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions Http/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,7 @@ m_LastTransmitted is not null && message is not null &&
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@SendHttpMessage: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}
finally
{
Expand Down
9 changes: 8 additions & 1 deletion Rtp/RtpClient.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,13 @@ private void HandleEvents()
HandleEvent();
}
}
catch (System.Exception ex) { Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@HandleEvents: " + ex.Message); goto Begin; }
catch (System.Exception ex)
{
Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@HandleEvents: " + ex.Message);
Media.Common.ILoggingExtensions.LogException(Logger, ex);

goto Begin;
}
}
}

Expand Down Expand Up @@ -2777,6 +2783,7 @@ private void SendReceieve()
catch (System.Exception ex)
{
Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@SendRecieve: " + ex.Message);
Media.Common.ILoggingExtensions.LogException(Logger, ex);

if (critical) System.Threading.Thread.EndCriticalRegion();

Expand Down
34 changes: 28 additions & 6 deletions Rtsp/RtspClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ public bool IsPlaying
catch (Exception ex)
{
Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@IsPlaying - " + ex.Message);
Media.Common.ILoggingExtensions.LogException(Logger, ex);
}
}

Expand Down Expand Up @@ -3083,7 +3084,7 @@ public void StopPlaying(IEnumerable<MediaDescription> mediaDescriptions, bool fo
public void StopPlaying(bool disconnectSocket = true)
{
try { Disconnect(disconnectSocket); }
catch (Exception ex) { Media.Common.ILoggingExtensions.Log(Logger, ex.Message); }
catch (Exception ex) { Media.Common.ILoggingExtensions.LogException(Logger, ex); }
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
Expand Down Expand Up @@ -3318,7 +3319,7 @@ message header.
}
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);

throw;
}
Expand Down Expand Up @@ -4623,6 +4624,7 @@ SharesSocket is false &&
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@SendRtspMessage: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}
finally
{
Expand Down Expand Up @@ -5967,7 +5969,11 @@ InUse is false &&
DisableKeepAliveRequest = keepAlives;
}
}
catch (Exception ex) { Common.ILoggingExtensions.Log(Logger, ToString() + "@MonitorProtocol: " + ex.Message); }
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@MonitorProtocol: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}

//If not disposed AND IsConnected and if protocol switch is still allowed AND IsPlaying and not already TCP
if (Common.IDisposedExtensions.IsNullOrDisposed(this) is false &&
Expand Down Expand Up @@ -6047,6 +6053,7 @@ tc.TotalPacketsSent is Common.Binary.LongZero &&
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@MonitorProtocol: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}
}
}
Expand All @@ -6070,8 +6077,19 @@ tc.TotalPacketsSent is Common.Binary.LongZero &&

//If there is still a timer change it based on the last messages round trip time, should be relative to all messages...
if (Common.IDisposedExtensions.IsNullOrDisposed(this) is false && m_ProtocolMonitor is not null)
try { m_ProtocolMonitor.Change(m_ConnectionTime.Add(LastMessageRoundTripTime), Media.Common.Extensions.TimeSpan.TimeSpanExtensions.InfiniteTimeSpan); }
catch (Exception ex) { Common.ILoggingExtensions.Log(Logger, ToString() + "@MonitorProtocol: " + ex.Message); }
try
{
m_ProtocolMonitor.Change
(
m_ConnectionTime.Add(LastMessageRoundTripTime),
Media.Common.Extensions.TimeSpan.TimeSpanExtensions.InfiniteTimeSpan
);
}
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@MonitorProtocol: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}
}

public RtspMessage SendPlay(MediaDescription mediaDescription, TimeSpan? startTime = null, TimeSpan? endTime = null, string rangeType = "npt")
Expand Down Expand Up @@ -6514,7 +6532,11 @@ context.Goodbye is null ||
}

}
catch (Exception ex) { Common.ILoggingExtensions.Log(Logger, ToString() + "@SendKeepAlive: " + ex.Message); }
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@SendKeepAlive: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}

//Raise the stopping event if not playing anymore
//if (true == wasPlaying && false == IsPlaying) OnStopping();
Expand Down
4 changes: 3 additions & 1 deletion Rtsp/RtspSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ public bool IsPlaying
catch (Exception ex)
{
Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@IsPlaying - " + ex.Message);
Media.Common.ILoggingExtensions.LogException(Logger, ex);
}
}

Expand Down Expand Up @@ -1702,6 +1703,7 @@ SharesSocket is false &&
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ToString() + "@SendRtspMessage: " + ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);
}
finally
{
Expand Down Expand Up @@ -2399,7 +2401,7 @@ message header.
}
catch (Exception ex)
{
Common.ILoggingExtensions.Log(Logger, ex.Message);
Common.ILoggingExtensions.LogException(Logger, ex);

throw;
}
Expand Down

0 comments on commit 945933f

Please sign in to comment.