Last active
August 29, 2015 14:03
-
-
Save DalSoft/d4ead3b2b4cca2cd1a72 to your computer and use it in GitHub Desktop.
Stop Raygun4Net logging RawData and other sensitive data
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
using System.Collections.Generic; | |
using System.Web; | |
using Mindscape.Raygun4Net.Messages; | |
namespace Logging.Extensions | |
{ | |
public static class Raygun4NetExtensions | |
{ | |
public static void SetNonSensitiveHttpDetails(this RaygunMessage message) | |
{ | |
var context = HttpContext.Current; | |
if (context == null) | |
return; | |
HttpRequest request = null; | |
try | |
{ | |
request = context.Request; | |
} | |
catch (HttpException) | |
{ | |
} | |
message.Details.Request = new SensitiveRaygunRequestMessage(request); | |
} | |
public class SensitiveRaygunRequestMessage : RaygunRequestMessage | |
{ | |
public SensitiveRaygunRequestMessage(HttpRequest request) : base(request, new List<string>()) | |
{ | |
//Remove sensitive data that Raygun logs by default | |
Data.Remove("HTTP_AUTHORIZATION"); | |
Headers.Remove("Authorization"); | |
QueryString = new Dictionary<string, string>(); | |
Form = new Dictionary<string, string>(); | |
Cookies = new List<string>(); | |
RawData = string.Empty; | |
} | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using Logging.Extensions; | |
using Mindscape.Raygun4Net; | |
namespace Logging | |
{ | |
public class RaygunLogger | |
{ | |
private readonly RaygunClient _raygun; | |
private readonly string _application; | |
private readonly string _buildNumber; | |
public RaygunLogger(RaygunClient raygun, string application, string buildNumber) | |
{ | |
_raygun = raygun; | |
_application = application; | |
_buildNumber = buildNumber; | |
} | |
public void Error(Exception ex) | |
{ | |
var message = RaygunMessageBuilder.New | |
.SetEnvironmentDetails() | |
.SetMachineName(Environment.MachineName) | |
.SetExceptionDetails(ex) | |
.SetClientDetails() | |
.SetVersion("Build: " + _buildNumber) | |
.SetTags(new[] {_application}) | |
.SetUserCustomData(new Dictionary<string,string>()) | |
.Build(); | |
message.SetNonSensitiveHttpDetails(); | |
_raygun.Send(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment