Adds minimum log level handling to the service

This commit is contained in:
Cyberboss
2018-09-27 12:03:24 -04:00
parent cb96060967
commit e6e504cc91
2 changed files with 17 additions and 3 deletions
+13 -1
View File
@@ -33,6 +33,18 @@ namespace Tgstation.Server.Host.Service
[Option(ShortName = "i")]
public bool Install { get; set; }
/// <summary>
/// The --trace or -t option. Enables trace logs
/// </summary>
[Option(ShortName = "t")]
public bool Trace { get; set; }
/// <summary>
/// The --debug or -d option. Enables debug logs
/// </summary>
[Option(ShortName = "d")]
public bool Debug { get; set; }
/// <summary>
/// Check if the running user is a system administrator
/// </summary>
@@ -109,7 +121,7 @@ namespace Tgstation.Server.Host.Service
}
else
using (var loggerFactory = new LoggerFactory())
ServiceBase.Run(new ServerService(new WatchdogFactory(), loggerFactory));
ServiceBase.Run(new ServerService(new WatchdogFactory(), loggerFactory, Trace ? LogLevel.Trace : Debug ? LogLevel.Debug : LogLevel.Information));
}
/// <summary>
@@ -41,7 +41,8 @@ namespace Tgstation.Server.Host.Service
/// </summary>
/// <param name="watchdogFactory">The <see cref="IWatchdogFactory"/> to create <see cref="watchdog"/> with</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> for <paramref name="watchdogFactory"/></param>
public ServerService(IWatchdogFactory watchdogFactory, ILoggerFactory loggerFactory)
/// <param name="minumumLogLevel">The minimum <see cref="LogLevel"/> to record in the event log</param>
public ServerService(IWatchdogFactory watchdogFactory, ILoggerFactory loggerFactory, LogLevel minumumLogLevel)
{
if (watchdogFactory == null)
throw new ArgumentNullException(nameof(watchdogFactory));
@@ -50,7 +51,8 @@ namespace Tgstation.Server.Host.Service
loggerFactory.AddEventLog(new EventLogSettings
{
EventLog = this
EventLog = this,
Filter = (message, logLevel) => logLevel >= minumumLogLevel
});
ServiceName = Name;