-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from serilog/dev
5.1.0 Release
- Loading branch information
Showing
7 changed files
with
323 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,3 +182,6 @@ UpgradeLog*.htm | |
# Microsoft Fakes | ||
FakesAssemblies/ | ||
.vs/ | ||
|
||
# Rider settings | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Serilog.Sinks.Raygun/Sinks/Raygun/LogEventPropertyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Collections; | ||
using System.Linq; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Raygun | ||
{ | ||
public static class LogEventPropertyExtensions | ||
{ | ||
public static string AsString(this LogEventProperty property) | ||
{ | ||
var scalar = property.Value as ScalarValue; | ||
return scalar?.Value != null ? property.Value.ToString("l", null) : null; | ||
} | ||
|
||
public static int AsInteger(this LogEventProperty property, int defaultIfNull = 0) | ||
{ | ||
var scalar = property.Value as ScalarValue; | ||
return scalar?.Value != null ? int.TryParse(property.Value.ToString(), out int result) ? result : defaultIfNull : defaultIfNull; | ||
} | ||
|
||
public static IDictionary AsDictionary(this LogEventProperty property) | ||
{ | ||
if (!(property.Value is DictionaryValue value)) return null; | ||
|
||
return value.Elements.ToDictionary( | ||
kv => kv.Key.ToString("l", null), | ||
kv => kv.Value is ScalarValue scalarValue ? scalarValue.Value : kv.Value); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/Serilog.Sinks.Raygun/Sinks/Raygun/RaygunClientHttpEnricher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#if NETSTANDARD2_0 | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Mindscape.Raygun4Net; | ||
using Mindscape.Raygun4Net.AspNetCore; | ||
using Mindscape.Raygun4Net.AspNetCore.Builders; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Raygun | ||
{ | ||
public class RaygunClientHttpEnricher : ILogEventEnricher | ||
{ | ||
public const string RaygunRequestMessagePropertyName = "RaygunSink_RequestMessage"; | ||
public const string RaygunResponseMessagePropertyName = "RaygunSink_ResponseMessage"; | ||
|
||
readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly LogEventLevel _restrictedToMinimumLevel; | ||
private readonly RaygunSettings _raygunSettings; | ||
|
||
public RaygunClientHttpEnricher(IHttpContextAccessor httpContextAccessor, LogEventLevel restrictedToMinimumLevel, RaygunSettings raygunSettings) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_restrictedToMinimumLevel = restrictedToMinimumLevel; | ||
_raygunSettings = raygunSettings; | ||
} | ||
|
||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
if (logEvent.Level < _restrictedToMinimumLevel) | ||
{ | ||
return; | ||
} | ||
|
||
if (_httpContextAccessor?.HttpContext == null) | ||
{ | ||
return; | ||
} | ||
|
||
var options = new RaygunRequestMessageOptions | ||
{ | ||
IsRawDataIgnored = _raygunSettings.IsRawDataIgnored, | ||
UseXmlRawDataFilter = _raygunSettings.UseXmlRawDataFilter, | ||
IsRawDataIgnoredWhenFilteringFailed = _raygunSettings.IsRawDataIgnoredWhenFilteringFailed, | ||
UseKeyValuePairRawDataFilter = _raygunSettings.UseKeyValuePairRawDataFilter | ||
}; | ||
|
||
options.AddCookieNames(_raygunSettings.IgnoreCookieNames ?? Array.Empty<string>()); | ||
options.AddHeaderNames(_raygunSettings.IgnoreHeaderNames ?? Array.Empty<string>()); | ||
options.AddFormFieldNames(_raygunSettings.IgnoreFormFieldNames ?? Array.Empty<string>()); | ||
options.AddQueryParameterNames(_raygunSettings.IgnoreQueryParameterNames ?? Array.Empty<string>()); | ||
options.AddSensitiveFieldNames(_raygunSettings.IgnoreSensitiveFieldNames ?? Array.Empty<string>()); | ||
options.AddServerVariableNames(_raygunSettings.IgnoreServerVariableNames ?? Array.Empty<string>()); | ||
|
||
RaygunRequestMessage httpRequestMessage = RaygunAspNetCoreRequestMessageBuilder | ||
.Build(_httpContextAccessor.HttpContext, options) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
RaygunResponseMessage httpResponseMessage = RaygunAspNetCoreResponseMessageBuilder.Build(_httpContextAccessor.HttpContext); | ||
|
||
// The Raygun request/response messages are stored in the logEvent properties collection. | ||
// When the error is sent to Raygun, these messages are extracted from the known properties | ||
// and then removed so as to not duplicate data in the payload. | ||
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(RaygunRequestMessagePropertyName, httpRequestMessage, true)); | ||
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(RaygunResponseMessagePropertyName, httpResponseMessage, true)); | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.