private static string FormatText(string message, string filePath, int lineNumber, string memberName) { const int sourceColumnMaxWidth = 23; EnsureArgument.NotNull(message, nameof(message)); EnsureArgument.NotNull(filePath, nameof(filePath)); EnsureArgument.PositiveOrZero(lineNumber, nameof(lineNumber)); EnsureArgument.NotNull(memberName, nameof(memberName)); // Source column format is file:line string source = $"{filePath}:{lineNumber}"; if (source.Length > sourceColumnMaxWidth) { int idx = 0; int maxlen = sourceColumnMaxWidth - 3; int srclen = source.Length; while (idx >= 0 && (srclen - idx) > maxlen) { idx = source.IndexOf('\\', idx + 1); } // If we cannot find a path separator which allows the path to be long enough, just truncate the file name if (idx < 0) { idx = srclen - maxlen; } source = "..." + source.Substring(idx); } // Git's trace format is "{timestamp,-15} {source,-23} trace: {details}" string text = $"{DateTime.Now:HH:mm:ss.ffffff} {source,-23} trace: [{memberName}] {message}"; return(text); }