Skip to content

Commit

Permalink
Added the possibility to generate a log message depending on the ``Lo…
Browse files Browse the repository at this point in the history
…gLevel`` (#91)
  • Loading branch information
lpeyr committed Apr 1, 2023
1 parent 1131619 commit 735c43d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions PeyrSharp.Env/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using PeyrSharp.Enums;
using System;
using System.IO;

Expand Down Expand Up @@ -72,5 +73,24 @@ public static void Log(string message, string filePath, params object[] formatSt

File.AppendAllText(filePath, string.Format(message, formatString)); // Log
}

/// <summary>
/// Logs a message with the specified severity level, file path, and timestamp.
/// </summary>
/// <param name="message">The message to log.</param>
/// <param name="filePath">The path to the file where the message was logged.</param>
/// <param name="dateTime">The timestamp for the log message.</param>
/// <param name="logLevel">The severity level for the log message.</param>
public static void Log(string message, string filePath, DateTime dateTime, LogLevel logLevel) => Log($"[{LogLevelToString(logLevel)}] {message}", filePath, dateTime);

private static string LogLevelToString(LogLevel level) => level switch
{
LogLevel.Error => "Error",
LogLevel.Warning => "Warning",
LogLevel.Info => "Info",
LogLevel.Critical => "Critical",
LogLevel.Debug => "Debug",
_ => "Misc"
};
}
}

0 comments on commit 735c43d

Please sign in to comment.