fix: Fixes structured logging (#1043)

- [X] Fixes various bugs in logging.
This commit is contained in:
Kamron Batman 2022-06-05 01:00:22 -07:00 committed by GitHub
parent 78bb4f4bb2
commit 6e69d25e33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 96 additions and 102 deletions

View file

@ -147,7 +147,7 @@ namespace Server
{
if (Running)
{
logger.Error($"Timer is returned while still running!\n{new StackTrace()}");
logger.Error("Timer is returned while still running!\n{StackTrace}", new StackTrace());
return;
}
@ -163,7 +163,7 @@ namespace Server
if (_poolCount >= _poolCapacity)
{
#if DEBUG_TIMERS
logger.Warning($"DelayCallTimer pool reached maximum of {_poolCapacity} timers");
logger.Warning("DelayCallTimer pool reached maximum of {Capacity} timers", _poolCapacity);
_allowFinalization = true;
#endif
return;
@ -181,7 +181,7 @@ namespace Server
if (timer != null)
{
#if DEBUG_TIMERS
logger.Information($"Getting from pool: ({_poolCount} / {_poolCapacity})");
logger.Information("Getting from pool: ({Count} / {Capacity})", _poolCount, _poolCapacity);
#endif
timer.Init(delay, interval, count);
@ -197,7 +197,7 @@ namespace Server
_timerPoolDepletionAmount++;
#if DEBUG_TIMERS
logger.Warning($"Timer pool depleted and timer was allocated.\n{new StackTrace()}");
logger.Warning("Timer pool depleted and timer was allocated.\n{StackTrace}", new StackTrace());
#endif
return new DelayCallTimer(delay, interval, count, callback);
}
@ -211,7 +211,7 @@ namespace Server
{
if (!_allowFinalization)
{
logger.Warning($"Pooled timer was not returned to the pool.\n{_stackTraces[GetHashCode()]}");
logger.Warning("Pooled timer was not returned to the pool.\n{StackTrace}", _stackTraces[GetHashCode()]);
}
}
#endif

View file

@ -41,8 +41,9 @@ namespace Server
var amountToRefill = Math.Min(_maxPoolCapacity, amountToGrow);
var maximumHit = amountToGrow > amountToRefill ? " Maximum pool size has been reached." : "";
var warningMessage = $"Timer pool depleted by {{Amount}}. Refilling with {{AmountRefill}}.{maximumHit}";
logger.Warning($"Timer pool depleted by {_timerPoolDepletionAmount}. Refilling with {amountToRefill}.{maximumHit}");
logger.Warning(warningMessage, _timerPoolDepletionAmount, amountToRefill);
RefillPoolAsync(amountToRefill);
_timerPoolDepletionAmount = 0;
}
@ -62,7 +63,7 @@ namespace Server
_poolHead = head;
_poolCount += amount;
#if DEBUG_TIMERS
logger.Information($"Returning to pool. ({_poolCount} / {_poolCapacity})");
logger.Information("Returning to pool. ({Count} / {Capacity})", _poolCount, _poolCapacity);
#endif
}
@ -84,7 +85,7 @@ namespace Server
internal static void RefillPool(int amount, out DelayCallTimer head, out DelayCallTimer tail)
{
#if DEBUG_TIMERS
logger.Information($"Filling pool with {amount} timers.");
logger.Information("Filling pool with {Amount} timers.", amount);
#endif
head = null;

View file

@ -199,7 +199,7 @@ namespace Server
// TODO: Handle timers > 17yrs
#if DEBUG_TIMERS
logger.Error($"Timer is more than max duration. ({originalDelay})");
logger.Error("Timer is more than max duration. ({Duration})", originalDelay);
#endif
}
@ -224,12 +224,12 @@ namespace Server
while (t != null)
{
var name = t.ToString();
hash.TryGetValue(name, out var count);
hash[name] = count + 1;
total++;
t = t?._nextTimer;
}
}