diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs index a87594a9..792c6711 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/ActivityController.cs @@ -3,10 +3,12 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Filter.Filters.Activity; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.StorableLists.Stores; using LBPUnion.ProjectLighthouse.Types.Activity; using LBPUnion.ProjectLighthouse.Types.Entities.Token; using LBPUnion.ProjectLighthouse.Types.Levels; +using LBPUnion.ProjectLighthouse.Types.Logging; using LBPUnion.ProjectLighthouse.Types.Serialization.Activity; using LBPUnion.ProjectLighthouse.Types.Users; using Microsoft.AspNetCore.Authorization; @@ -121,7 +123,7 @@ public class ActivityController : ControllerBase dto.Activity.Type != EventType.AddLevelToPlaylist); } - Console.WriteLine(predicate); + Logger.Debug(predicate.ToString(), LogArea.Activity); dtoQuery = dtoQuery.Where(predicate); @@ -281,16 +283,16 @@ public class ActivityController : ControllerBase { foreach (OuterActivityGroup outer in outerGroups) { - Console.WriteLine(@$"Outer group key: {outer.Key}"); + Logger.Debug(@$"Outer group key: {outer.Key}", LogArea.Activity); List> itemGroup = outer.Groups; foreach (IGrouping item in itemGroup) { - Console.WriteLine( - @$" Inner group key: TargetId={item.Key.TargetId}, UserId={item.Key.UserId}, Type={item.Key.Type}"); + Logger.Debug( + @$" Inner group key: TargetId={item.Key.TargetId}, UserId={item.Key.UserId}, Type={item.Key.Type}", LogArea.Activity); foreach (ActivityDto activity in item) { - Console.WriteLine( - @$" Activity: {activity.GroupType}, Timestamp: {activity.Activity.Timestamp}, UserId: {activity.Activity.UserId}, EventType: {activity.Activity.Type}, TargetId: {activity.TargetId}"); + Logger.Debug( + @$" Activity: {activity.GroupType}, Timestamp: {activity.Activity.Timestamp}, UserId: {activity.Activity.UserId}, EventType: {activity.Activity.Type}, TargetId: {activity.TargetId}", LogArea.Activity); } } } diff --git a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs index 741f8149..33390375 100644 --- a/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs +++ b/ProjectLighthouse/Types/Activity/ActivityEntityEventHandler.cs @@ -2,12 +2,14 @@ using System; using System.Linq; using LBPUnion.ProjectLighthouse.Database; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types.Entities.Activity; using LBPUnion.ProjectLighthouse.Types.Entities.Interaction; using LBPUnion.ProjectLighthouse.Types.Entities.Level; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Website; using LBPUnion.ProjectLighthouse.Types.Levels; +using LBPUnion.ProjectLighthouse.Types.Logging; using Microsoft.EntityFrameworkCore; #if DEBUG using System.ComponentModel.DataAnnotations.Schema; @@ -20,7 +22,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler { public void OnEntityInserted(DatabaseContext database, T entity) where T : class { - Console.WriteLine($@"OnEntityInserted: {entity.GetType().Name}"); + Logger.Debug($@"OnEntityInserted: {entity.GetType().Name}", LogArea.Activity); ActivityEntity? activity = entity switch { SlotEntity slot => slot.Type switch @@ -125,7 +127,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler { if (activity == null) return; - Console.WriteLine("Inserting activity: " + activity.GetType().Name); + Logger.Debug("Inserting activity: " + activity.GetType().Name, LogArea.Activity); activity.Timestamp = DateTime.UtcNow; database.Activities.Add(activity); @@ -145,11 +147,11 @@ public class ActivityEntityEventHandler : IEntityEventHandler object? newVal = propInfo.GetValue(currentEntity); if ((origVal == null && newVal == null) || (origVal != null && newVal != null && origVal.Equals(newVal))) continue; - Console.WriteLine($@"Value for {propInfo.Name} changed"); - Console.WriteLine($@"Orig val: {origVal?.ToString() ?? "null"}"); - Console.WriteLine($@"New val: {newVal?.ToString() ?? "null"}"); + Logger.Debug($@"Value for {propInfo.Name} changed", LogArea.Activity); + Logger.Debug($@"Orig val: {origVal?.ToString() ?? "null"}", LogArea.Activity); + Logger.Debug($@"New val: {newVal?.ToString() ?? "null"}", LogArea.Activity); } - Console.WriteLine($@"OnEntityChanged: {currentEntity.GetType().Name}"); + Logger.Debug($@"OnEntityChanged: {currentEntity.GetType().Name}", LogArea.Activity); #endif ActivityEntity? activity = null; @@ -242,12 +244,12 @@ public class ActivityEntityEventHandler : IEntityEventHandler int[] newSlots = playlist.SlotIds; int[] oldSlots = oldPlaylist.SlotIds; - Console.WriteLine($@"Old playlist slots: {string.Join(",", oldSlots)}"); - Console.WriteLine($@"New playlist slots: {string.Join(",", newSlots)}"); + Logger.Debug($@"Old playlist slots: {string.Join(",", oldSlots)}", LogArea.Activity); + Logger.Debug($@"New playlist slots: {string.Join(",", newSlots)}", LogArea.Activity); int[] addedSlots = newSlots.Except(oldSlots).ToArray(); - Console.WriteLine($@"Added playlist slots: {string.Join(",", addedSlots)}"); + Logger.Debug($@"Added playlist slots: {string.Join(",", addedSlots)}", LogArea.Activity); // If no new level have been added if (addedSlots.Length == 0) break; @@ -275,7 +277,7 @@ public class ActivityEntityEventHandler : IEntityEventHandler public void OnEntityDeleted(DatabaseContext database, T entity) where T : class { - Console.WriteLine($@"OnEntityDeleted: {entity.GetType().Name}"); + Logger.Debug($@"OnEntityDeleted: {entity.GetType().Name}", LogArea.Activity); ActivityEntity? activity = entity switch { HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch diff --git a/ProjectLighthouse/Types/Logging/LogArea.cs b/ProjectLighthouse/Types/Logging/LogArea.cs index 10146e22..9a8cc178 100644 --- a/ProjectLighthouse/Types/Logging/LogArea.cs +++ b/ProjectLighthouse/Types/Logging/LogArea.cs @@ -28,4 +28,5 @@ public enum LogArea Email, Serialization, Synchronization, + Activity, } \ No newline at end of file diff --git a/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs b/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs index c9b8079f..d69d626f 100644 --- a/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs +++ b/ProjectLighthouse/Types/Serialization/Activity/Events/GameEvent.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; using System.Xml.Serialization; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types.Activity; using LBPUnion.ProjectLighthouse.Types.Entities.Activity; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; +using LBPUnion.ProjectLighthouse.Types.Logging; using LBPUnion.ProjectLighthouse.Types.Serialization.Review; namespace LBPUnion.ProjectLighthouse.Types.Serialization.Activity.Events; @@ -46,7 +48,9 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization protected async Task PrepareSerialization(DatabaseContext database) { - Console.WriteLine($@"EVENT SERIALIZATION!! {this.UserId} - {this.GetHashCode()}"); + #if DEBUG + Logger.Debug($@"EVENT SERIALIZATION!! userId: {this.UserId} - hashCode: {this.GetHashCode()}", LogArea.Activity); + #endif UserEntity user = await database.Users.FindAsync(this.UserId); if (user == null) return; this.Username = user.Username; @@ -114,7 +118,7 @@ public class GameEvent : ILbpSerializable, INeedsPreparationForSerialization { if (!IsValidActivity(activity.Activity)) { - Console.WriteLine(@"Invalid Activity: " + activity.Activity.ActivityId); + Logger.Error(@"Invalid Activity: " + activity.Activity.ActivityId, LogArea.Activity); return null; }