public void Log([FromBody] ClientExceptionContract clientException) { ThrowIf.Null(clientException, nameof(clientException)); if (string.IsNullOrWhiteSpace(clientException.CorrelationId)) { clientException.CorrelationId = HttpContext.GetCorrelationId(); } string message = this.LogFormatter.FormatClientException(clientException); this.Logger.LogError(ApplicationLogEvents.ClientError, message); }
public void FormatClientException_Always_ReturnsCorretStringRepresentation() { var formatter = new LogFormatter(); var exception = new ClientExceptionContract() { ClientPlatform = "Chrome", CorrelationId = "qc-123", ErrorCode = "UNEXPECTED", Message = "Test error", StackTrace = "TestModule.MyFunc" }; string formattedMessage = formatter.FormatClientException(exception); Assert.Equal("qc-123: CLIENT UNEXPECTED - Test error at TestModule.MyFunc (Chrome)", formattedMessage); }
/// <summary> /// Formats log message for client exception. /// </summary> /// <param name="exception">Client exception.</param> /// <returns>Formatted log message for client exception.</returns> public string FormatClientException(ClientExceptionContract exception) { return($"{exception.CorrelationId}: CLIENT {exception.ErrorCode} - {exception.Message} at {exception.StackTrace} ({exception.ClientPlatform})"); }