mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Add ServerType to file logs
This commit is contained in:
parent
09994769da
commit
7ff2d3f1a2
5 changed files with 17 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Configuration;
|
||||
|
||||
|
@ -25,6 +26,7 @@ public static class ServerStatics
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: This needs to go at some point.
|
||||
public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName!.StartsWith("xunit"));
|
||||
|
||||
#if DEBUG
|
||||
|
@ -32,4 +34,10 @@ public static class ServerStatics
|
|||
#else
|
||||
public static readonly bool IsDebug = false;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The servertype, determined on startup. Shouldn't be null unless very very early in startup.
|
||||
/// </summary>
|
||||
// The way of doing this is kinda weird, but it works.
|
||||
public static ServerType ServerType;
|
||||
}
|
|
@ -11,7 +11,8 @@ public class ConsoleLogger : ILogger
|
|||
|
||||
foreach (string line in logLine.Message.Split('\n'))
|
||||
{
|
||||
// The following is scuffed. Beware~
|
||||
// The following is scuffed.
|
||||
// Beware~
|
||||
|
||||
// Write the level! [Success]
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Logging.Loggers;
|
||||
|
||||
public class LighthouseFileLogger : ILogger
|
||||
public class FileLogger : ILogger
|
||||
{
|
||||
private static readonly string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs");
|
||||
|
||||
|
@ -13,8 +13,8 @@ public class LighthouseFileLogger : ILogger
|
|||
{
|
||||
FileHelper.EnsureDirectoryCreated(logsDirectory);
|
||||
|
||||
string contentFile = $"[{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string contentAll = $"[{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string contentFile = $"[{ServerStatics.ServerType}] [{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
string contentAll = $"[{ServerStatics.ServerType}] [{line.Area}:{line.Level}] <{line.Trace.Name}:{line.Trace.Section}> {line.Message}\n";
|
||||
|
||||
try
|
||||
{
|
|
@ -20,7 +20,6 @@ public class DebugWarmupLifetime : IHostLifetime
|
|||
private CancellationTokenRegistration applicationStartedRegistration;
|
||||
|
||||
private readonly ConsoleLifetime consoleLifetime;
|
||||
public static ServerType ServerType;
|
||||
|
||||
public DebugWarmupLifetime
|
||||
(
|
||||
|
@ -39,7 +38,7 @@ public class DebugWarmupLifetime : IHostLifetime
|
|||
{
|
||||
using HttpClient client = new();
|
||||
|
||||
string url = ServerType switch
|
||||
string url = ServerStatics.ServerType switch
|
||||
{
|
||||
ServerType.GameServer => ServerConfiguration.Instance.GameApiListenUrl,
|
||||
ServerType.Website => ServerConfiguration.Instance.WebsiteListenUrl,
|
||||
|
|
|
@ -24,13 +24,11 @@ public static class StartupTasks
|
|||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
|
||||
#if DEBUG
|
||||
DebugWarmupLifetime.ServerType = serverType;
|
||||
#endif
|
||||
ServerStatics.ServerType = serverType;
|
||||
|
||||
// Setup logging
|
||||
Logger.Instance.AddLogger(new ConsoleLogger());
|
||||
Logger.Instance.AddLogger(new LighthouseFileLogger());
|
||||
Logger.Instance.AddLogger(new FileLogger());
|
||||
|
||||
Logger.Info($"Welcome to the Project Lighthouse {serverType.ToString()}!", LogArea.Startup);
|
||||
Logger.Info($"You are running version {VersionHelper.FullVersion}", LogArea.Startup);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue