From e6e504cc91cb9251ece6ba841b0575a0dace847f Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 27 Sep 2018 12:03:24 -0400 Subject: [PATCH] Adds minimum log level handling to the service --- src/Tgstation.Server.Host.Service/Program.cs | 14 +++++++++++++- src/Tgstation.Server.Host.Service/ServerService.cs | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 5944978b4d..69db326c2f 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -33,6 +33,18 @@ namespace Tgstation.Server.Host.Service [Option(ShortName = "i")] public bool Install { get; set; } + /// + /// The --trace or -t option. Enables trace logs + /// + [Option(ShortName = "t")] + public bool Trace { get; set; } + + /// + /// The --debug or -d option. Enables debug logs + /// + [Option(ShortName = "d")] + public bool Debug { get; set; } + /// /// Check if the running user is a system administrator /// @@ -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)); } /// diff --git a/src/Tgstation.Server.Host.Service/ServerService.cs b/src/Tgstation.Server.Host.Service/ServerService.cs index 58c923afe2..1f53f5e999 100644 --- a/src/Tgstation.Server.Host.Service/ServerService.cs +++ b/src/Tgstation.Server.Host.Service/ServerService.cs @@ -41,7 +41,8 @@ namespace Tgstation.Server.Host.Service /// /// The to create with /// The for - public ServerService(IWatchdogFactory watchdogFactory, ILoggerFactory loggerFactory) + /// The minimum to record in the event log + 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;