From 723bbe38cc3ca144187b5fee12c65622eee3914b Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 27 Oct 2020 08:28:09 +1000 Subject: [PATCH 1/6] Dev version bump [skip ci] --- src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj b/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj index 757fdfb..16c3e04 100644 --- a/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj +++ b/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj @@ -14,7 +14,7 @@ serilog sink raygun Copyright © Serilog Contributors 2017-2020 Serilog event sink that writes to the Raygun service. - 5.0.1 + 5.0.2 From b15e7194c459b7947f36b72ed39b91f7187e1c2d Mon Sep 17 00:00:00 2001 From: QuantumNightmare Date: Tue, 1 Jun 2021 17:11:10 +1200 Subject: [PATCH 2/6] Fix stacktrace when no exception is provided --- .../Sinks/Raygun/NullException.cs | 21 +++++++++++++++++++ .../Sinks/Raygun/RaygunSink.cs | 15 ++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs new file mode 100644 index 0000000..4028474 --- /dev/null +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs @@ -0,0 +1,21 @@ +using System; +using System.Diagnostics; + +namespace Serilog.Sinks.Raygun.Sinks.Raygun +{ + // This is used to carry the code execution StackTrace from the Serilog Sink to the Raygun callback in the case that no exception has been provided. + internal class NullException : Exception + { + private readonly StackTrace _stackTrace; + + public NullException(StackTrace stacktrace) + { + _stackTrace = stacktrace; + } + + public StackTrace StackTrace + { + get { return _stackTrace; } + } + } +} diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs index 0a0635c..a0b47f8 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs @@ -26,6 +26,7 @@ #endif using Serilog.Core; using Serilog.Events; +using Serilog.Sinks.Raygun.Sinks.Raygun; namespace Serilog.Sinks.Raygun { @@ -92,9 +93,9 @@ public RaygunSink(IFormatProvider formatProvider, _client.AddWrapperExceptions(wrapperExceptions.ToArray()); if(ignoredFormFieldNames != null) - _client.IgnoreFormFieldNames(ignoredFormFieldNames.ToArray()); + _client.IgnoreFormFieldNames(ignoredFormFieldNames.ToArray()); - _client.SendingMessage += OnSendingMessage; + _client.CustomGroupingKey += OnCustomGroupingKey; } /// @@ -124,15 +125,15 @@ public void Emit(LogEvent logEvent) // Submit if (logEvent.Level == LogEventLevel.Fatal) { - _client.Send(logEvent.Exception, tags, properties); + _client.Send(logEvent.Exception ?? new NullException(new StackTrace()), tags, properties); } else { - _client.SendInBackground(logEvent.Exception, tags, properties); + _client.SendInBackground(logEvent.Exception ?? new NullException(new StackTrace()), tags, properties); } } - private void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e) + private void OnCustomGroupingKey(object sender, RaygunCustomGroupingKeyEventArgs e) { if (e?.Message?.Details != null) { @@ -148,13 +149,13 @@ private void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e) if (details.UserCustomData is Dictionary properties) { // If an Exception has not been provided, then use the log message/template to fill in the details and attach the current execution stack - if (details.Error == null) + if (e.Exception is NullException nullException) { details.Error = new RaygunErrorMessage { ClassName = properties[LogMessageTemplateProperty].ToString("l", null), Message = properties[RenderedLogMessageProperty].ToString("l", null), - StackTrace = RaygunErrorMessageBuilder.BuildStackTrace(new StackTrace()) + StackTrace = RaygunErrorMessageBuilder.BuildStackTrace(nullException.StackTrace) }; } From 38ac712f55ec0edf6d4595b566228dcf734f229e Mon Sep 17 00:00:00 2001 From: QuantumNightmare Date: Sat, 5 Jun 2021 08:35:33 +1200 Subject: [PATCH 3/6] Strip Serilog classes from the current execution stack --- .../Sinks/Raygun/RaygunSink.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs index a0b47f8..b12c859 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs @@ -125,11 +125,11 @@ public void Emit(LogEvent logEvent) // Submit if (logEvent.Level == LogEventLevel.Fatal) { - _client.Send(logEvent.Exception ?? new NullException(new StackTrace()), tags, properties); + _client.Send(logEvent.Exception ?? new NullException(GetCurrentExecutionStackTrace()), tags, properties); } else { - _client.SendInBackground(logEvent.Exception ?? new NullException(new StackTrace()), tags, properties); + _client.SendInBackground(logEvent.Exception ?? new NullException(GetCurrentExecutionStackTrace()), tags, properties); } } @@ -226,6 +226,24 @@ occurredOnPropertyValue is ScalarValue occurredOnScalar && } } + private static StackTrace GetCurrentExecutionStackTrace() + { + StackTrace stackTrace = new StackTrace(); + + for (int frameIndex = 0; frameIndex < stackTrace.FrameCount; frameIndex++) + { + MethodBase method = stackTrace.GetFrame(frameIndex).GetMethod(); + string className = method?.ReflectedType?.FullName ?? ""; + + if (!className.StartsWith("Serilog.")) + { + return new StackTrace(frameIndex); + } + } + + return stackTrace; + } + private static RaygunIdentifierMessage BuildUserInformationFromStructureValue(StructureValue userStructure) { RaygunIdentifierMessage userIdentifier = new RaygunIdentifierMessage(null); From a363247c87e06538b8fd2ab8165b27a7b0f9ea6c Mon Sep 17 00:00:00 2001 From: QuantumNightmare Date: Mon, 21 Jun 2021 13:56:34 +1200 Subject: [PATCH 4/6] Changed property name to avoid build warning --- src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs | 2 +- src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs index 4028474..947c63b 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs @@ -13,7 +13,7 @@ public NullException(StackTrace stacktrace) _stackTrace = stacktrace; } - public StackTrace StackTrace + public StackTrace CodeExecutionStackTrace { get { return _stackTrace; } } diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs index b12c859..d6e10fe 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs @@ -155,7 +155,7 @@ private void OnCustomGroupingKey(object sender, RaygunCustomGroupingKeyEventArgs { ClassName = properties[LogMessageTemplateProperty].ToString("l", null), Message = properties[RenderedLogMessageProperty].ToString("l", null), - StackTrace = RaygunErrorMessageBuilder.BuildStackTrace(nullException.StackTrace) + StackTrace = RaygunErrorMessageBuilder.BuildStackTrace(nullException.CodeExecutionStackTrace) }; } From 07c88b23bd3129c5c11890dbbc3d076ee98102e9 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 21 Jun 2021 15:40:55 +1000 Subject: [PATCH 5/6] Update publishing key --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index bbc8551..5dddc0f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,7 +12,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf + secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5 skip_symbols: true on: branch: /^(master|dev)$/ From f7dc0e50a8a6cf20290ad4eea6e62626293e0ba3 Mon Sep 17 00:00:00 2001 From: QuantumNightmare Date: Tue, 22 Jun 2021 10:57:05 +1200 Subject: [PATCH 6/6] fix namespace --- src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj | 1 + src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs | 2 +- src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj b/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj index 16c3e04..7e9f368 100644 --- a/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj +++ b/src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj @@ -15,6 +15,7 @@ Copyright © Serilog Contributors 2017-2020 Serilog event sink that writes to the Raygun service. 5.0.2 + Serilog diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs index 947c63b..8921a00 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace Serilog.Sinks.Raygun.Sinks.Raygun +namespace Serilog.Sinks.Raygun { // This is used to carry the code execution StackTrace from the Serilog Sink to the Raygun callback in the case that no exception has been provided. internal class NullException : Exception diff --git a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs index d6e10fe..5fff58b 100644 --- a/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs +++ b/src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs @@ -26,7 +26,6 @@ #endif using Serilog.Core; using Serilog.Events; -using Serilog.Sinks.Raygun.Sinks.Raygun; namespace Serilog.Sinks.Raygun {