private LoggingEvent HandlePropertiesBuildingException(Exception ex, Severity severity) { var properties = new PropertiesDictionary(); if (_exception != null) { properties["Original.Exception.Message"] = _exception.Message; properties["Original.Exception.StackTrace"] = _exception.StackTrace; } if (!string.IsNullOrEmpty(_message)) { properties["Original.Message"] = _message; } try { properties["Exception"] = new LoggableException(ex); } catch { properties["Exception.Message"] = ex.Message; properties["Exception.StackTrace"] = ex.StackTrace; } properties["MachineName"] = Environment.MachineName; var eventData = new LoggingEventData { Message = "Error building log properties", Properties = properties, Level = severity.ToLog4NetLevel() }; return(new LoggingEvent(eventData)); }
public void Should_sanitize_passwords_from_loggable_exception() { string expectedValue = "{\"user\":{\"************\":\"****\"},\"userPreferences\":{\"currency\":\"USD\",\"siteId\":\"UnitedStates\",\"language\":\"en-US\",\"timeZone\":\"UTC\"},\"profile\":{}}"; var exception = new Exception(); exception.Data["APIRequestContent"] = "{\"user\":{\"password\":\"foobar484634198\"},\"userPreferences\":{\"currency\":\"USD\",\"siteId\":\"UnitedStates\",\"language\":\"en-US\",\"timeZone\":\"UTC\"},\"profile\":{}}"; var loggableException = new LoggableException(exception); loggableException.Data["APIRequestContent"].ShouldBeEquivalentTo(expectedValue); }
private static FormattedException FormatException(LoggableException exception) { var message = new FormattedException { Message = exception.Message, EnvironmentStackTrace = Environment.StackTrace, Source = exception.Source, StackTrace = exception.StackTrace, TargetSite = exception.TargetSite.IfNotNull(x => x.ToString()) }; if (exception.InnerException != null) { message.InnerException = FormatException(exception.InnerException); } return(message); }
public Flow(LoggableException exception) { Fail(exception); }
/// <summary> /// Fails the flow to be processed by an FailureBlock with a loggable exception. /// </summary> public void Fail(LoggableException exception) { Exception = exception; }