fix: Makes logging more consistent (#1246)

This commit is contained in:
Kamron Batman 2022-11-13 00:36:23 -08:00 committed by GitHub
parent 8e0d01d4be
commit d8cfb6b935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 90 additions and 69 deletions

View file

@ -75,7 +75,7 @@ public partial class Timer
t.Start();
#if DEBUG_TIMERS
DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}\n{new StackTrace()}";
DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}{Environment.NewLine}{new StackTrace()}";
#endif
}
@ -102,7 +102,7 @@ public partial class Timer
t.Start();
#if DEBUG_TIMERS
DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}\n{new StackTrace()}";
DelayCallTimer._stackTraces[t.GetHashCode()] = $"{callback.Method.Name}{Environment.NewLine}{new StackTrace()}";
#endif
token = new TimerExecutionToken(t);
}
@ -184,7 +184,7 @@ public partial class Timer
}
#if DEBUG_TIMERS
logger.Warning("Timer pool depleted and timer was allocated.\n{StackTrace}", new StackTrace());
logger.Warning($"Timer pool depleted and timer was allocated.{Environment.NewLine}{{StackTrace}}", new StackTrace());
#endif
return new DelayCallTimer(delay, interval, count, callback);
}
@ -198,7 +198,7 @@ public partial class Timer
{
if (!_allowFinalization)
{
logger.Warning("Pooled timer was not returned to the pool.\n{StackTrace}", _stackTraces[GetHashCode()]);
logger.Warning($"Pooled timer was not returned to the pool.{Environment.NewLine}{{StackTrace}}", _stackTraces[GetHashCode()]);
}
}
#endif

View file

@ -199,7 +199,7 @@ public partial class Timer
if (lastRing && slot > _ringSize)
{
logger.Error(
"Timer {Timer} has a duration of {Duration}ms, more than max capacity of {MaxDuration}ms.\n{StackTrace}",
$"Timer {{Timer}} has a duration of {{Duration}}ms, more than max capacity of {{MaxDuration}}ms.{Environment.NewLine}{{StackTrace}}",
timer.GetType(),
originalDelay,
_maxDuration,
@ -228,8 +228,8 @@ public partial class Timer
public static void DumpInfo(TextWriter tw)
{
tw.WriteLine($"Date: {Core.Now.ToLocalTime()}\n");
tw.WriteLine($"Pool - Count: {_poolCount}; Capacity {_poolCapacity}\n");
tw.WriteLine($"Date: {Core.Now.ToLocalTime()}{Environment.NewLine}");
tw.WriteLine($"Pool - Count: {_poolCount}; Capacity {_poolCapacity}{Environment.NewLine}");
var total = 0.0;
var hash = new Dictionary<string, int>();

View file

@ -82,7 +82,7 @@ public partial class Timer
if (World.WorldState is WorldState.Saving)
{
logger.Error(
"Attempted to start timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}",
$"Attempted to start timer {{Timer}} ({{HashCode}}) while world is {{State}}{Environment.NewLine}{{StackTrace}}",
GetType(),
GetHashCode(),
World.WorldState,
@ -94,7 +94,7 @@ public partial class Timer
if (Thread.CurrentThread != Core.Thread)
{
logger.Error(
"Attempted to start timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}",
$"Attempted to start timer {{Timer}} ({{HashCode}}) from an invalid thread!{Environment.NewLine}{{StackTrace}}",
GetType(),
GetHashCode(),
new StackTrace()
@ -126,7 +126,7 @@ public partial class Timer
if (World.WorldState is WorldState.Saving)
{
logger.Error(
"Attempted to stop timer {Timer} ({HashCode}) while world is {State}\n{StackTrace}",
$"Attempted to stop timer {{Timer}} ({{HashCode}}) while world is {{State}}{Environment.NewLine}{{StackTrace}}",
GetType(),
GetHashCode(),
World.WorldState,
@ -138,7 +138,7 @@ public partial class Timer
if (Thread.CurrentThread != Core.Thread)
{
logger.Error(
"Attempted to stop timer {Timer} ({HashCode}) from an invalid thread!\n{StackTrace}",
$"Attempted to stop timer {{Timer}} ({{HashCode}}) from an invalid thread!{Environment.NewLine}{{StackTrace}}",
GetType(),
GetHashCode(),
new StackTrace()
@ -231,7 +231,11 @@ public partial class Timer
{
if (Running)
{
logger.Error("{Timer} detached while still running!\n{StackTrace}", this, new StackTrace());
logger.Error(
$"{{Timer}} detached while still running!{Environment.NewLine}{{StackTrace}}",
this,
new StackTrace()
);
return;
}