Began implementing explicit log flushing.

This commit is contained in:
Harrison Deng 2020-12-25 03:45:24 -06:00
parent e4f2ebf792
commit acd735d9df
3 changed files with 18 additions and 4 deletions

View File

@ -6,9 +6,14 @@ namespace GameServiceWarden.Host.Logging
{ {
public LogLevel Level => LogLevel.INFO; public LogLevel Level => LogLevel.INFO;
public void Flush()
{
throw new NotImplementedException();
}
public void LogMessage(string message, DateTime time, LogLevel level) public void LogMessage(string message, DateTime time, LogLevel level)
{ {
throw new NotImplementedException();
} }
} }
} }

View File

@ -17,5 +17,10 @@ namespace GameServiceWarden.Host.Logging
/// <param name="time">The time at which this message was requested to be logged.</param> /// <param name="time">The time at which this message was requested to be logged.</param>
/// <param name="level">The severity of this message.</param> /// <param name="level">The severity of this message.</param>
void LogMessage(string message, DateTime time, LogLevel level); void LogMessage(string message, DateTime time, LogLevel level);
/// <summary>
/// Called when this receiver should explicitly flush received messages.
/// </summary>
void Flush();
} }
} }

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace GameServiceWarden.Host.Logging namespace GameServiceWarden.Host.Logging
{ {
public class Logger { public class Logger {
private HashSet<ILogReceiver> listeners = new HashSet<ILogReceiver>(); private readonly HashSet<ILogReceiver> listeners = new HashSet<ILogReceiver>();
/// <summary> /// <summary>
/// Logs the message to listeners that are listening to the set severity of the message or greater. /// Logs the message to listeners that are listening to the set severity of the message or greater.
@ -39,8 +39,12 @@ namespace GameServiceWarden.Host.Logging
/// <summary> /// <summary>
/// Called when all listeners should perform any flushing they need. /// Called when all listeners should perform any flushing they need.
/// </summary> /// </summary>
public static void FlushListeners() { public void FlushListeners()
{
foreach (ILogReceiver listener in listeners)
{
listener.Flush();
}
} }
} }
} }