Skip to content

Commit

Permalink
chore: remove homebrew Intersect logging and replace with Serilog and…
Browse files Browse the repository at this point in the history
… Microsoft ILogger
  • Loading branch information
lodicolo committed Jan 20, 2025
1 parent 540033b commit 971bcc7
Show file tree
Hide file tree
Showing 485 changed files with 1,507 additions and 3,614 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// NUnit 3 tests
// See documentation : https://github.com/nunit/docs/wiki/NUnit-Documentation
using Intersect.Plugins.Loaders;

using NUnit.Framework;

namespace Intersect.Examples.Plugin.Client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using CommandLine;

using Intersect.Utilities;

using System;

namespace Intersect.Examples.Plugin.Client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Intersect.Plugins;

using Newtonsoft.Json;

namespace Intersect.Examples.Plugin.Client
Expand Down
2 changes: 0 additions & 2 deletions Examples/Intersect.Examples.Plugin.Client/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Intersect.Plugins.Interfaces;
using Intersect.Plugins.Manifests.Types;
using Intersect.Utilities;

using Semver;

using System;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Intersect.Examples.Plugin.Packets.Client;
using Intersect.Examples.Plugin.Packets.Server;
using Intersect.Logging;
using Intersect.Network;

using System;

namespace Intersect.Examples.Plugin.Client.PacketHandlers
Expand All @@ -21,15 +19,15 @@ public bool Handle(IPacketSender packetSender, ExamplePluginServerPacket packet)
throw new ArgumentNullException(nameof(packet));
}

Log.Info($"Received server packet! The server said '{packet.ExamplePluginMessage}'.");
ApplicationContext.Context.Value?.Logger.LogInformation($"Received server packet! The server said '{packet.ExamplePluginMessage}'.");

var packetSent = packetSender.Send(new ExamplePluginClientPacket("A message from the client!"));
if (packetSent)
{
Log.Info("Sent response back to the server!");
ApplicationContext.Context.Value?.Logger.LogInformation("Sent response back to the server!");
} else
{
Log.Error("Failed to send response back to the server!");
ApplicationContext.Context.Value?.Logger.LogError("Failed to send response back to the server!");
}

return packetSent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Intersect.Network.Packets.Client;
using Intersect.Plugins;
using Intersect.Server.Plugins;

using System;

namespace Intersect.Examples.Plugin.Server
Expand Down
2 changes: 0 additions & 2 deletions Examples/Intersect.Examples.Plugin.Server/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Intersect.Plugins.Interfaces;
using Intersect.Plugins.Manifests.Types;
using Intersect.Utilities;

using Semver;

using System;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Intersect.Examples.Plugin.Packets.Client;
using Intersect.Logging;
using Intersect.Network;

namespace Intersect.Examples.Plugin.Server.Networking.Handlers
Expand All @@ -8,7 +7,7 @@ public class ExamplePluginClientPacketHandler : IPacketHandler<ExamplePluginClie
{
public bool Handle(IPacketSender packetSender, ExamplePluginClientPacket packet)
{
Log.Info($"Received example plugin response from the client: {packet.ExamplePluginMessage}");
ApplicationContext.Context.Value?.Logger.LogInformation($"Received example plugin response from the client: {packet.ExamplePluginMessage}");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Intersect.Examples.Plugin.Packets.Server;
using Intersect.Logging;
using Intersect.Network;
using Intersect.Network.Packets.Client;

Expand All @@ -12,11 +11,11 @@ public bool Handle(IPacketSender packetSender, LoginPacket packet)
var packetSent = packetSender.Send(new ExamplePluginServerPacket($"Login packet received: {packet.Username}"));
if (packetSent)
{
Log.Info("Sent a message to the client!");
ApplicationContext.Context.Value?.Logger.LogInformation("Sent a message to the client!");
}
else
{
Log.Error("Failed to send a message to the client!");
ApplicationContext.Context.Value?.Logger.LogError("Failed to send a message to the client!");
}

return packetSent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Intersect.Network;

using MessagePack;

namespace Intersect.Examples.Plugin.Packets.Client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Intersect.Network;

using MessagePack;

namespace Intersect.Examples.Plugin.Packets.Server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections;
using System.Text;
using Intersect.Core;
using Intersect.Enums;
using Intersect.Logging;
using Intersect.Framework.Reflection;
using Intersect.Models;
using Intersect.Utilities;
using Microsoft.Extensions.Logging;

namespace Intersect.Collections;

Expand Down Expand Up @@ -73,9 +75,12 @@ public List<IDatabaseObject> ValueList
}
catch (Exception exception)
{
LegacyLogging.Logger?.Warn(
ApplicationContext.Context.Value?.Logger.LogWarning(
exception,
$@"{StoredType.Name}[Count={mIdMap.Count},NullCount={mIdMap.Count(pair => pair.Value == null)}]"
"{StoredType}[Count={Count}, Null={NullCount}]",
StoredType.GetName(qualified: true),
mIdMap.Count,
mIdMap.Count(pair => pair.Value == null)
);

throw;
Expand Down
5 changes: 2 additions & 3 deletions Framework/Intersect.Framework.Core/Config/DatabaseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand Down Expand Up @@ -31,8 +30,8 @@ public partial class DatabaseOptions
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Populate
)]
[DefaultValue(Logging.LogLevel.Error)]
public Logging.LogLevel LogLevel { get; set; } = Logging.LogLevel.Error;
[DefaultValue(Microsoft.Extensions.Logging.LogLevel.Error)]
public Microsoft.Extensions.Logging.LogLevel LogLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Error;

public bool KillServerOnConcurrencyException { get; set; } = DefaultKillServerOnConcurrencyException;
}
7 changes: 5 additions & 2 deletions Framework/Intersect.Framework.Core/Config/LoggingOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Intersect.Logging;
using Intersect.Framework.Core.Serialization;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Intersect.Config;

public partial class LoggingOptions
{
public LogLevel Level { get; set; } = LogLevel.Info;
[JsonConverter(typeof(SafeStringEnumConverter))]
public LogLevel Level { get; set; } = LogLevel.Information;

/// <summary>
/// Determines whether chat logs should be written into the logging database
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;

namespace Intersect.Config;
Expand Down
1 change: 0 additions & 1 deletion Framework/Intersect.Framework.Core/Config/Passability.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.Serialization;

using Newtonsoft.Json;

namespace Intersect.Config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.ComponentModel;
using System.Runtime.Serialization;

using Intersect.Enums;
using Intersect.Logging;
using Intersect.Utilities;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Intersect.Configuration;
Expand Down Expand Up @@ -264,8 +263,8 @@ public void Validate()
#region Hidden Properties

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
[DefaultValue(LogLevel.Info)]
public LogLevel LogLevel { get; set; } = LogLevel.Info;
[DefaultValue(LogLevel.Information)]
public LogLevel LogLevel { get; set; } = LogLevel.Information;

#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text;

using Intersect.Core;
using Intersect.Framework.Reflection;
using Intersect.IO.Files;
using Intersect.Logging;

using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace Intersect.Configuration;
Expand Down Expand Up @@ -34,7 +34,12 @@ public static T Load<T>(T configuration, string filePath, bool failQuietly = fal
}
catch (Exception exception)
{
LegacyLogging.Logger?.Error(exception);
ApplicationContext.Context.Value?.Logger.LogError(
exception,
"Error when reading {ConfigurationType} from {FilePath}",
typeof(T).GetName(qualified: true),
filePath
);

throw;
}
Expand All @@ -46,12 +51,12 @@ public static T Save<T>(T configuration, string filePath, bool failQuietly = fal
var directoryPath = Path.GetDirectoryName(filePath);
if (directoryPath == null)
{
throw new ArgumentNullException();
throw new ArgumentException($"'{filePath}' has no directory name", nameof(filePath));
}

if (!FileSystemHelper.EnsureDirectoryExists(directoryPath))
{
throw new FileNotFoundException("Missing directory.", directoryPath);
throw new DirectoryNotFoundException($"Directory does not exist: {directoryPath}");
}

try
Expand All @@ -64,7 +69,12 @@ public static T Save<T>(T configuration, string filePath, bool failQuietly = fal
}
catch (Exception exception)
{
LegacyLogging.Logger?.Error(exception);
ApplicationContext.Context.Value?.Logger.LogError(
exception,
"Error when writing {ConfigurationType} to {FilePath}",
typeof(T).GetName(qualified: true),
filePath
);

throw;
}
Expand All @@ -84,7 +94,12 @@ public static T LoadSafely<T>(T configuration, string filePath = null)
}
catch (Exception exception)
{
LegacyLogging.Logger?.Warn(exception);
ApplicationContext.Context.Value?.Logger.LogWarning(
exception,
"Error when reading {ConfigurationType} to {FilePath}",
typeof(T).GetName(qualified: true),
filePath
);
}
finally
{
Expand All @@ -94,7 +109,12 @@ public static T LoadSafely<T>(T configuration, string filePath = null)
}
catch (Exception exception)
{
LegacyLogging.Logger?.Error(exception);
ApplicationContext.Context.Value?.Logger.LogError(
exception,
"Error when writing {ConfigurationType} to {FilePath}",
typeof(T).GetName(qualified: true),
filePath
);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Framework/Intersect.Framework.Core/Core/ApplicationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Intersect.Core;

public static class ApplicationContext
{
public static readonly AsyncLocal<IApplicationContext?> Context = new();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Intersect.Logging;

using Intersect.Plugins.Interfaces;
using Intersect.Threading;
using Microsoft.Extensions.Logging;

namespace Intersect.Core;

Expand Down Expand Up @@ -63,8 +64,8 @@ public interface IApplicationContext : IDisposable
void Start(bool lockUntilShutdown = true);

/// <summary>
/// Start the application with a <see cref="LockingActionQueue"/>.
/// Start the application with a <see cref="ILockingActionQueue"/>.
/// </summary>
/// <returns>the <see cref="LockingActionQueue"/> instance being used</returns>
/// <returns>the <see cref="ILockingActionQueue"/> instance being used</returns>
ILockingActionQueue StartWithActionQueue();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Intersect.Logging;

using Intersect.Core;
using Microsoft.Extensions.Logging;
using NCalc;

namespace Intersect.Server.Utilities;
Expand Down Expand Up @@ -45,7 +45,7 @@ protected virtual void Exp(FunctionArgs args)
{
if (args.Parameters == null || args.Parameters.Length < 3)
{
LegacyLogging.Logger?.Error("Tried to execute Exp with fewer than three arguments.");
ApplicationContext.Context.Value?.Logger.LogError("Tried to execute Exp with fewer than three arguments.");
args.Result = 0L;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.ComponentModel.DataAnnotations.Schema;
using Intersect.Models;

using Microsoft.EntityFrameworkCore;

using Newtonsoft.Json;

namespace Intersect.GameObjects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;

using Intersect.Localization;

namespace Intersect.GameObjects.Annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Intersect.Localization;

#if !DEBUG
using Intersect.Logging;

#endif

namespace Intersect.GameObjects.Annotations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Reflection;

using Intersect.Localization;

#if !DEBUG
using Intersect.Logging;

#endif

namespace Intersect.GameObjects.Annotations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;

using Intersect.Collections;
using Intersect.GameObjects.Maps;
using Intersect.GameObjects.Maps.MapList;
Expand Down
Loading

0 comments on commit 971bcc7

Please sign in to comment.