new logging system
This commit is contained in:
28
DTLib.Logging/LogFormats/DefaultLogFormat.cs
Normal file
28
DTLib.Logging/LogFormats/DefaultLogFormat.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace DTLib.Logging.New;
|
||||
|
||||
public class DefaultLogFormat : ILogFormat
|
||||
{
|
||||
|
||||
public bool PrintTimeStamp { get; set; }
|
||||
public bool PrintContext { get; set; }
|
||||
public bool PrintSeverity { get; set; }
|
||||
|
||||
public DefaultLogFormat(bool printTimeStamp = false, bool printContext = true, bool printSeverity = true)
|
||||
{
|
||||
PrintTimeStamp = printTimeStamp;
|
||||
PrintContext = printContext;
|
||||
PrintSeverity = printSeverity;
|
||||
}
|
||||
|
||||
public string CreateMessage(string context, LogSeverity severity, object message)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (PrintTimeStamp) sb.Append('[').Append(DateTime.Now.ToString(MyTimeFormat.ForText)).Append(']');
|
||||
if(PrintContext) sb.Append('[').Append(context).Append(']');
|
||||
if(PrintSeverity) sb.Append('[').Append(severity.ToString()).Append(']');
|
||||
if (sb.Length != 0) sb.Append(": ");
|
||||
sb.Append(message.ToString());
|
||||
sb.Append('\n');
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
10
DTLib.Logging/LogFormats/ILogFormat.cs
Normal file
10
DTLib.Logging/LogFormats/ILogFormat.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DTLib.Logging.New;
|
||||
|
||||
public interface ILogFormat
|
||||
{
|
||||
bool PrintTimeStamp { get; set; }
|
||||
bool PrintContext { get; set; }
|
||||
bool PrintSeverity { get; set; }
|
||||
|
||||
string CreateMessage(string context, LogSeverity severity, object message);
|
||||
}
|
||||
Reference in New Issue
Block a user