Outsourced default format string for logging into the LogFormatter
This commit is contained in:
parent
fd9d4241fb
commit
8add6b467d
|
@ -18,6 +18,7 @@ namespace SweetLib.Utils.Logger
|
|||
public static class Logger
|
||||
{
|
||||
public static LogLevel GlobalLogLevel { get; set; } = LogLevel.Info | LogLevel.Warn | LogLevel.Error;
|
||||
|
||||
public static ILogMemory DefaultLogMemory = new ArchivableConsoleLogMemory();
|
||||
|
||||
public static void Log(LogLevel logLevel, string message)
|
||||
|
|
|
@ -13,11 +13,12 @@ namespace SweetLib.Utils.Logger.Memory
|
|||
{
|
||||
private string TempFile { get; } = Path.GetTempFileName();
|
||||
|
||||
private Timer QueueTimer;
|
||||
private Timer QueueTimer { get; }
|
||||
|
||||
private ConcurrentQueue<LogMessage> LogQueue { get; } = new ConcurrentQueue<LogMessage>();
|
||||
|
||||
public string ArchiveFile { get; set; } = null;
|
||||
|
||||
public bool AutoArchiveOnDispose { get; set; } = true;
|
||||
|
||||
public ArchivableConsoleLogMemory() : this(null) { }
|
||||
|
|
|
@ -5,7 +5,9 @@ namespace SweetLib.Utils.Logger.Memory
|
|||
public interface ILogMemory
|
||||
{
|
||||
void Remember(LogMessage message);
|
||||
|
||||
void Forget(LogMessage message);
|
||||
|
||||
void Archive(string fullFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ namespace SweetLib.Utils.Logger.Message
|
|||
public class LogMessage : IFormattable
|
||||
{
|
||||
public LogLevel LogLevel { get; }
|
||||
|
||||
public string Message { get; }
|
||||
|
||||
public DateTime LogDateTime { get; }
|
||||
|
||||
public LogMessage(LogLevel logLevel, string message) : this(logLevel, message, DateTime.Now) { }
|
||||
|
@ -26,7 +28,7 @@ namespace SweetLib.Utils.Logger.Message
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString($"[{CultureInfo.CurrentCulture.DateTimeFormat}] (LL) - V", CultureInfo.CurrentCulture);
|
||||
return ToString(LogMessageFormatter.DefaultFormatString, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace SweetLib.Utils.Logger.Message
|
||||
{
|
||||
public class LogMessageFormatter : ICustomFormatter
|
||||
{
|
||||
|
||||
private LogMessageFormatter() { }
|
||||
private static LogMessageFormatter FormatterInstance { get; set; }
|
||||
|
||||
private static object Locker { get; } = new object();
|
||||
|
||||
public static LogMessageFormatter FormatterInstance { get; set; }
|
||||
|
||||
public static string DefaultFormatString { get; set; } = $"[{CultureInfo.CurrentCulture.DateTimeFormat}] (LL) - V";
|
||||
|
||||
public static LogMessageFormatter Instance
|
||||
{
|
||||
get
|
||||
|
|
Loading…
Reference in a new issue