From fa9c5ac6892cb99e2513ec536ce0c3ff164f53d9 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 3 Nov 2024 21:44:03 +0500 Subject: [PATCH] log format --- DTLib/Logging/LogFormats/DefaultLogFormat.cs | 17 +++++------------ DTLib/Logging/LogFormats/ILogFormat.cs | 4 ---- DTLib/MyTimeFormat.cs | 2 ++ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/DTLib/Logging/LogFormats/DefaultLogFormat.cs b/DTLib/Logging/LogFormats/DefaultLogFormat.cs index ec3d5b5..245178a 100644 --- a/DTLib/Logging/LogFormats/DefaultLogFormat.cs +++ b/DTLib/Logging/LogFormats/DefaultLogFormat.cs @@ -2,23 +2,16 @@ namespace DTLib.Logging; public class DefaultLogFormat : ILogFormat { - - public bool PrintTimeStamp { get; set; } - public bool PrintContext { get; set; } - public bool PrintSeverity { get; set; } - - public DefaultLogFormat(bool printTimeStamp = true, bool printContext = true, bool printSeverity = true) - { - PrintTimeStamp = printTimeStamp; - PrintContext = printContext; - PrintSeverity = printSeverity; - } + public bool PrintTimeStamp { get; set; } = true; + public bool PrintContext { get; set; } = true; + public bool PrintSeverity { get; set; } = true; + public string TimeStampFormat { get; set; } = MyTimeFormat.ForText; public string CreateMessage(string context, LogSeverity severity, object message) { var sb = new StringBuilder(); if (PrintTimeStamp) - sb.Append('[').Append(DateTime.Now.ToString(MyTimeFormat.ForText)).Append(']'); + sb.Append('[').Append(DateTime.Now.ToString(TimeStampFormat)).Append(']'); if (PrintContext && PrintSeverity) sb.Append('[').Append(context).Append('/').Append(severity.ToString()).Append(']'); else if(PrintContext) diff --git a/DTLib/Logging/LogFormats/ILogFormat.cs b/DTLib/Logging/LogFormats/ILogFormat.cs index caa8321..a916a74 100644 --- a/DTLib/Logging/LogFormats/ILogFormat.cs +++ b/DTLib/Logging/LogFormats/ILogFormat.cs @@ -2,9 +2,5 @@ namespace DTLib.Logging; public interface ILogFormat { - bool PrintTimeStamp { get; set; } - bool PrintContext { get; set; } - bool PrintSeverity { get; set; } - string CreateMessage(string context, LogSeverity severity, object message); } \ No newline at end of file diff --git a/DTLib/MyTimeFormat.cs b/DTLib/MyTimeFormat.cs index 765b5c8..59cdd66 100644 --- a/DTLib/MyTimeFormat.cs +++ b/DTLib/MyTimeFormat.cs @@ -4,4 +4,6 @@ public static class MyTimeFormat { public const string ForFileNames="yyyy.MM.dd_HH-mm-ss_zz"; public const string ForText="yyyy.MM.dd HH:mm:ss zz"; + public const string TimeOnly="HH:mm:ss"; + public const string DateOnly="yyyy.MM.dd"; } \ No newline at end of file