log format
This commit is contained in:
parent
613b11e88c
commit
fa9c5ac689
@ -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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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";
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user