| | | 1 | | namespace ArturRios.Extensions; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Provides extension methods for Exceptions, including utilities to format an exception into a log line. |
| | | 5 | | /// </summary> |
| | | 6 | | public static class ExceptionExtensions |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Formats exception details into a single log line and outputs a generated trace identifier. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="exception">The exception to format.</param> |
| | | 12 | | /// <param name="traceId">The generated trace identifier associated with this log entry.</param> |
| | | 13 | | /// <returns>A single-line string containing timestamp, trace id, exception type, message and stack trace.</returns> |
| | | 14 | | public static string ToLogLine(this Exception exception, out Guid traceId) |
| | 3 | 15 | | { |
| | 3 | 16 | | traceId = Guid.NewGuid(); |
| | | 17 | | |
| | 3 | 18 | | return |
| | 3 | 19 | | $"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} | TraceId: {traceId} | Exception: {exception.GetType().Name} | Messa |
| | 2 | 20 | | } |
| | | 21 | | } |