public void Should_sanitize_creditCard() { var loggingProperties = new LoggingEventPropertiesBuilder() .Build(); loggingProperties.Set("someInfo", "\"EmailAddress\\\":\\\"[email protected]\\\",\\\"creditCard\\\":\\\"1234123412341234\\\""); loggingProperties.Set("moreInfo", "\"emailAddress\":\"[email protected]\",\"creditCard\":\"1234123412341234\""); Assert.AreEqual(loggingProperties["someInfo"], "\"EmailAddress\\\":\\\"[email protected]\\\",\\\"************\\\":\\\"****\\\""); Assert.AreEqual(loggingProperties["moreInfo"], "\"emailAddress\":\"[email protected]\",\"************\":\"****\""); }
public void Should_Have_Different_Origin_When_Message_Is_Different() { var exception = GetSystemParseExceptionA(); var loggingPropertiesA = new LoggingEventPropertiesBuilder() .WithException(exception) .WithUniqueOrigin(string.Empty, exception) .Build(); var loggingPropertiesB = new LoggingEventPropertiesBuilder() .WithException(exception) .WithUniqueOrigin("This is a custom message", exception) .Build(); Assert.AreNotEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString()); }
public void Should_Have_Same_Origin_When_Exception_Thrown_From_And_Not_From_Excluded_Method() { var exceptionA = GetVariableSystemException(parseException: true); var exceptionB = GetVariableSystemException(parseException: true, throwViaMethod: true); var loggingPropertiesA = new LoggingEventPropertiesBuilder() .WithException(exceptionA) .WithUniqueOrigin(string.Empty, exceptionA) .Build(); var loggingPropertiesB = new LoggingEventPropertiesBuilder() .WithException(exceptionB) .WithUniqueOrigin(string.Empty, exceptionB) .Build(); Assert.AreEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString()); }
public void Should_Have_Same_Origin_When_Custom_Messages_Are_The_Same_But_Exceptions_Are_Different() { var exceptionA = GetVariableSystemException(parseException: true); var exceptionB = GetVariableSystemException(argumentException: true); var loggingPropertiesA = new LoggingEventPropertiesBuilder() .WithException(exceptionA) .WithUniqueOrigin("This is a custom message", exceptionA) .Build(); var loggingPropertiesB = new LoggingEventPropertiesBuilder() .WithException(exceptionB) .WithUniqueOrigin("This is a custom message", exceptionB) .Build(); Assert.AreEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString()); }
public void Should_Have_Different_Origin_When_First_Target_Stack_Trace_Is_Same_But_Exceptions_Differ() { var exceptionA = GetVariableSystemException(parseException: true); var loggingPropertiesA = new LoggingEventPropertiesBuilder() .WithException(exceptionA) .WithUniqueOrigin(string.Empty, exceptionA) .Build(); var exceptionB = GetVariableSystemException(argumentException: true); var loggingPropertiesB = new LoggingEventPropertiesBuilder() .WithException(exceptionB) .WithUniqueOrigin(string.Empty, exceptionB) .Build(); Assert.AreNotEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString()); }
public void Write() { if (!_severity.HasValue) { _severity = _exception != null ? Logging.Severity.Error : Logging.Severity.Info; } Action x = () => { LoggingEvent loggingEvent; try { var loggingEventContextBuilder = new LoggingEventPropertiesBuilder() .WithMachineName() .WithSqlData(_sql, _sqlParameters) .WithException(_exception) .WithCurrentVersion() .WithUniqueOrigin(_message, _exception) .ToContextBuilder() .WithRequest(_request) .WithResponse(_response) .IncludeBasicRequestInfo(); if (!_shouldOmitRequestBody) { loggingEventContextBuilder = loggingEventContextBuilder.IncludeRequestBody(_advancedOptions.TruncateRequestBodyCharactersTo); } var properties = loggingEventContextBuilder .IncludeResponse(_advancedOptions.TruncateResponseBodyCharactersTo) .FinishContext() .WithTags(_tags) .WithAdditionalData(_data) .Build(); var frame = new StackTrace().GetFrame(0); var eventData = _loggingEventDataBuilder.Build(frame, _severity.Value, _message, _exception, properties); loggingEvent = new LoggingEvent(eventData); } catch (Exception ex) { loggingEvent = HandlePropertiesBuildingException(ex, _severity.Value); } try { _log.Logger.Log(loggingEvent); } catch (Exception e) { // We need something here eventually, if logstash is down we lose logs Console.WriteLine("Failed to send messages to Logstash: " + e); } }; if (UseAsync) { Task.Factory.StartNew(x); } else { x(); } }