Skip to content

Commit

Permalink
Merge pull request #39 from serilog/dev
Browse files Browse the repository at this point in the history
5.0.2 Release
  • Loading branch information
QuantumNightmare authored Jun 21, 2021
2 parents ef44627 + 76fd5bd commit 423c279
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
3 changes: 2 additions & 1 deletion src/Serilog.Sinks.Raygun/Serilog.Sinks.Raygun.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<PackageTags>serilog sink raygun</PackageTags>
<Copyright>Copyright © Serilog Contributors 2017-2020</Copyright>
<Description>Serilog event sink that writes to the Raygun service.</Description>
<VersionPrefix>5.0.1</VersionPrefix>
<VersionPrefix>5.0.2</VersionPrefix>
<RootNamespace>Serilog</RootNamespace>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
Expand Down
21 changes: 21 additions & 0 deletions src/Serilog.Sinks.Raygun/Sinks/Raygun/NullException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Diagnostics;

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
{
private readonly StackTrace _stackTrace;

public NullException(StackTrace stacktrace)
{
_stackTrace = stacktrace;
}

public StackTrace CodeExecutionStackTrace
{
get { return _stackTrace; }
}
}
}
32 changes: 25 additions & 7 deletions src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,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;
}

/// <summary>
Expand Down Expand Up @@ -124,15 +124,15 @@ public void Emit(LogEvent logEvent)
// Submit
if (logEvent.Level == LogEventLevel.Fatal)
{
_client.Send(logEvent.Exception, tags, properties);
_client.Send(logEvent.Exception ?? new NullException(GetCurrentExecutionStackTrace()), tags, properties);
}
else
{
_client.SendInBackground(logEvent.Exception, tags, properties);
_client.SendInBackground(logEvent.Exception ?? new NullException(GetCurrentExecutionStackTrace()), tags, properties);
}
}

private void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e)
private void OnCustomGroupingKey(object sender, RaygunCustomGroupingKeyEventArgs e)
{
if (e?.Message?.Details != null)
{
Expand All @@ -148,13 +148,13 @@ private void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e)
if (details.UserCustomData is Dictionary<string, LogEventPropertyValue> 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.CodeExecutionStackTrace)
};
}

Expand Down Expand Up @@ -225,6 +225,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);
Expand Down

0 comments on commit 423c279

Please sign in to comment.