Skip to content

Commit a05d0f2

Browse files
authored
fix: better logging (AscensionGameDev#2091)
1 parent 26d7cb0 commit a05d0f2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Intersect.Network/LiteNetLib/AesGcmAlgorithm.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ public override EncryptionResult TryDecrypt(ReadOnlySpan<byte> cipherdata, out R
134134
Log.Debug($"cipherdataView({cipherdataView.Length})={Convert.ToHexString(cipherdataView)}");
135135
Log.Debug($"key={Convert.ToHexString(_key.Span)}");
136136
#endif
137-
Log.Error(exception);
137+
var configuredLogLevel = Options.Instance?.Logging.Level ?? LogLevel.Diagnostic;
138+
if (configuredLogLevel < LogLevel.Debug)
139+
{
140+
Log.Error(exception);
141+
}
138142
plaindata = default;
139143
return EncryptionResult.Error;
140144
}
@@ -207,7 +211,11 @@ public override EncryptionResult TryEncrypt(ReadOnlySpan<byte> plaindata, out Re
207211
}
208212
catch (Exception exception)
209213
{
210-
Log.Error(exception);
214+
var configuredLogLevel = Options.Instance?.Logging.Level ?? LogLevel.Diagnostic;
215+
if (configuredLogLevel < LogLevel.Debug)
216+
{
217+
Log.Error(exception);
218+
}
211219
cipherdata = default;
212220
return EncryptionResult.Error;
213221
}

Intersect.Server.Core/Database/IntersectDbContext.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Intersect.Logging;
77
using Intersect.Reflection;
88
using Intersect.Server.Core;
9+
using Intersect.Server.Database.PlayerData.Players;
10+
using Intersect.Server.Entities;
911
using Microsoft.EntityFrameworkCore;
1012
using Microsoft.EntityFrameworkCore.ChangeTracking;
1113
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -207,13 +209,42 @@ public override int SaveChanges(bool acceptAllChangesOnSuccess)
207209
}
208210
catch (DbUpdateConcurrencyException concurrencyException)
209211
{
212+
static Guid GetUserIdFrom(object entry)
213+
{
214+
return entry switch
215+
{
216+
IPlayerOwned playerOwned => playerOwned.Player?.User?.Id ?? playerOwned.Player?.UserId ?? default,
217+
Player player => player.User?.Id ?? player.UserId,
218+
_ => default,
219+
};
220+
}
221+
210222
var concurrencyErrors = new StringBuilder();
223+
var userIds = concurrencyException.Entries.Select(GetUserIdFrom)
224+
.Where(id => id != default)
225+
.Distinct()
226+
.ToArray();
227+
if (userIds.Length == 1)
228+
{
229+
concurrencyErrors.AppendLine($"This failure was wholly caused by user {userIds.First()}");
230+
}
231+
else
232+
{
233+
concurrencyErrors.AppendLine($"Involved users: {string.Join(", ", userIds)}");
234+
}
235+
211236
foreach (var entry in concurrencyException.Entries)
212237
{
213238
concurrencyErrors.AppendLine(
214239
$"[{entry.State}] {entry.Entity.GetFullishName()} ({entry.GetFullishName()})"
215240
);
216241

242+
var userId = GetUserIdFrom(entry.Entity);
243+
if (userId != default)
244+
{
245+
concurrencyErrors.AppendLine($"User Id {userId}");
246+
}
247+
217248
var proposedValues = entry.CurrentValues;
218249
var databaseValues = entry.GetDatabaseValues();
219250

0 commit comments

Comments
 (0)