| | | 1 | | using ArturRios.Extensions; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Logging.Factories; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Factory for creating formatted log entry strings. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class LogEntryFactory |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Creates a formatted log entry string with timestamp, log level, class name, method name, and message. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="level">The log level.</param> |
| | | 14 | | /// <param name="filePath">The source file path.</param> |
| | | 15 | | /// <param name="methodName">The calling method name.</param> |
| | | 16 | | /// <param name="message">The log message.</param> |
| | | 17 | | /// <returns>A formatted log entry string.</returns> |
| | | 18 | | public static string Create(CustomLogLevel level, string filePath, string methodName, string message) |
| | 38 | 19 | | => Create(level, filePath, methodName, message, DateTime.UtcNow); |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Creates a formatted log entry stamped with <paramref name="timestamp"/>, so a caller that also derives a file |
| | | 23 | | /// name from the time can use the same instant for both. |
| | | 24 | | /// </summary> |
| | | 25 | | internal static string Create(CustomLogLevel level, string filePath, string methodName, string message, |
| | | 26 | | DateTime timestamp) |
| | | 27 | | { |
| | 114 | 28 | | var logLevel = level.GetDescription()!; |
| | 114 | 29 | | var className = Path.GetFileNameWithoutExtension(filePath); |
| | | 30 | | |
| | 114 | 31 | | return $"{logLevel}: {className} | {methodName} | {timestamp:o} | {message}{Environment.NewLine}"; |
| | | 32 | | } |
| | | 33 | | } |