diff --git a/BepInEx.Core/Logging/BepInExLogInterpolatedStringHandler.cs b/BepInEx.Core/Logging/BepInExLogInterpolatedStringHandler.cs
index 16460b6..c5620df 100644
--- a/BepInEx.Core/Logging/BepInExLogInterpolatedStringHandler.cs
+++ b/BepInEx.Core/Logging/BepInExLogInterpolatedStringHandler.cs
@@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
using System.Text;
using BepInEx.Logging;
-namespace BepInEx.Core.Logging;
+namespace BepInEx.Core.Logging.Interpolation;
///
/// Interpolated string handler for BepInEx . This allows to conditionally skip logging certain
@@ -99,3 +99,69 @@ public class BepInExLogInterpolatedStringHandler
///
public override string ToString() => sb?.ToString() ?? string.Empty;
}
+
+///
+[InterpolatedStringHandler]
+public class BepInExFatalLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExFatalLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Fatal, out isEnabled) { }
+}
+
+///
+[InterpolatedStringHandler]
+public class BepInExErrorLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExErrorLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Error, out isEnabled) { }
+}
+
+///
+[InterpolatedStringHandler]
+public class BepInExWarningLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExWarningLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Warning, out isEnabled) { }
+}
+
+///
+[InterpolatedStringHandler]
+public class BepInExMessageLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExMessageLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Message, out isEnabled) { }
+}
+
+///
+[InterpolatedStringHandler]
+public class BepInExInfoLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExInfoLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Info, out isEnabled) { }
+}
+
+///
+[InterpolatedStringHandler]
+public class BepInExDebugLogInterpolatedStringHandler : BepInExLogInterpolatedStringHandler
+{
+ ///
+ public BepInExDebugLogInterpolatedStringHandler(int literalLength,
+ int formattedCount,
+ out bool isEnabled) : base(literalLength, formattedCount,
+ LogLevel.Debug, out isEnabled) { }
+}
diff --git a/BepInEx.Core/Logging/Logger.cs b/BepInEx.Core/Logging/Logger.cs
index 3fb0ff8..e78842e 100644
--- a/BepInEx.Core/Logging/Logger.cs
+++ b/BepInEx.Core/Logging/Logger.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
-using BepInEx.Core.Logging;
+using BepInEx.Core.Logging.Interpolation;
namespace BepInEx.Logging;
diff --git a/BepInEx.Core/Logging/ManualLogSource.cs b/BepInEx.Core/Logging/ManualLogSource.cs
index 880204c..f59263b 100644
--- a/BepInEx.Core/Logging/ManualLogSource.cs
+++ b/BepInEx.Core/Logging/ManualLogSource.cs
@@ -1,6 +1,6 @@
using System;
using System.Runtime.CompilerServices;
-using BepInEx.Core.Logging;
+using BepInEx.Core.Logging.Interpolation;
namespace BepInEx.Logging;
@@ -34,8 +34,14 @@ public class ManualLogSource : ILogSource
/// Data to log.
public void Log(LogLevel level, object data) => LogEvent?.Invoke(this, new LogEventArgs(data, level, this));
+ ///
+ /// Logs an interpolated string with the specified log level.
+ ///
+ /// Log levels to attach to the message. Multiple can be used with bitwise ORing.
+ /// Handler for the interpolated string.
public void Log(LogLevel level,
- [InterpolatedStringHandlerArgument("level")] BepInExLogInterpolatedStringHandler logHandler)
+ [InterpolatedStringHandlerArgument("level")]
+ BepInExLogInterpolatedStringHandler logHandler)
{
if (logHandler.Enabled)
LogEvent?.Invoke(this, new LogEventArgs(logHandler.ToString(), level, this));
@@ -47,33 +53,69 @@ public class ManualLogSource : ILogSource
/// Data to log.
public void LogFatal(object data) => Log(LogLevel.Fatal, data);
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogFatal(BepInExFatalLogInterpolatedStringHandler logHandler) => Log(LogLevel.Fatal, logHandler);
+
///
/// Logs a message with level.
///
/// Data to log.
public void LogError(object data) => Log(LogLevel.Error, data);
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogError(BepInExErrorLogInterpolatedStringHandler logHandler) => Log(LogLevel.Error, logHandler);
+
///
/// Logs a message with level.
///
/// Data to log.
public void LogWarning(object data) => Log(LogLevel.Warning, data);
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogWarning(BepInExWarningLogInterpolatedStringHandler logHandler) => Log(LogLevel.Warning, logHandler);
+
///
/// Logs a message with level.
///
/// Data to log.
public void LogMessage(object data) => Log(LogLevel.Message, data);
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogMessage(BepInExMessageLogInterpolatedStringHandler logHandler) => Log(LogLevel.Message, logHandler);
+
///
/// Logs a message with level.
///
/// Data to log.
public void LogInfo(object data) => Log(LogLevel.Info, data);
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogInfo(BepInExInfoLogInterpolatedStringHandler logHandler) => Log(LogLevel.Info, logHandler);
+
///
/// Logs a message with level.
///
/// Data to log.
public void LogDebug(object data) => Log(LogLevel.Debug, data);
+
+ ///
+ /// Logs an interpolated string with level.
+ ///
+ /// Handler for the interpolated string.
+ public void LogDebug(BepInExDebugLogInterpolatedStringHandler logHandler) => Log(LogLevel.Debug, logHandler);
}
diff --git a/BepInEx.Core/Logging/TraceLogSource.cs b/BepInEx.Core/Logging/TraceLogSource.cs
index 964d856..d73be2d 100644
--- a/BepInEx.Core/Logging/TraceLogSource.cs
+++ b/BepInEx.Core/Logging/TraceLogSource.cs
@@ -48,13 +48,13 @@ public class TraceLogSource : TraceListener
/// Writes a message to the underlying instance.
///
/// The message to write.
- public override void Write(string message) => LogSource.LogInfo(message);
+ public override void Write(string message) => LogSource.Log(LogLevel.Info, message);
///
/// Writes a message and a newline to the underlying instance.
///
/// The message to write.
- public override void WriteLine(string message) => LogSource.LogInfo(message);
+ public override void WriteLine(string message) => LogSource.Log(LogLevel.Info, message);
///
public override void TraceEvent(TraceEventCache eventCache,
diff --git a/BepInEx.IL2CPP/Hook/FastNativeDetour.cs b/BepInEx.IL2CPP/Hook/FastNativeDetour.cs
index d06c8be..3edcc0d 100644
--- a/BepInEx.IL2CPP/Hook/FastNativeDetour.cs
+++ b/BepInEx.IL2CPP/Hook/FastNativeDetour.cs
@@ -104,7 +104,7 @@ public class FastNativeDetour : IDetour
{
debuggerLogSource
.LogDebug($"Detouring 0x{OriginalFunctionPtr.ToString("X")} -> 0x{DetourFunctionPtr.ToString("X")}");
- debuggerLogSource.LogDebug("Original (32) asm");
+ debuggerLogSource.Log(LogLevel.Debug, "Original (32) asm");
DetourGenerator.Disassemble(debuggerLogSource, OriginalFunctionPtr, 32);
}
@@ -116,10 +116,10 @@ public class FastNativeDetour : IDetour
if (debuggerLogSource != null)
{
- debuggerLogSource.LogDebug($"Trampoline allocation: 0x{TrampolinePtr.ToString("X")}");
- debuggerLogSource.LogDebug("Modified (32) asm");
+ debuggerLogSource.Log(LogLevel.Debug, $"Trampoline allocation: 0x{TrampolinePtr.ToString("X")}");
+ debuggerLogSource.Log(LogLevel.Debug, "Modified (32) asm");
DetourGenerator.Disassemble(debuggerLogSource, OriginalFunctionPtr, 32);
- debuggerLogSource.LogDebug($"Trampoline ({trampolineLength}) asm");
+ debuggerLogSource.Log(LogLevel.Debug, $"Trampoline ({trampolineLength}) asm");
DetourGenerator.Disassemble(debuggerLogSource, TrampolinePtr, trampolineLength);
}
diff --git a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
index 2eacd8f..43e3fa5 100644
--- a/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
+++ b/BepInEx.IL2CPP/Hook/IL2CPPDetourMethodPatcher.cs
@@ -275,7 +275,7 @@ public unsafe class IL2CPPDetourMethodPatcher : MethodPatcher
return dmd;
}
- private static void ReportException(Exception ex) => DetourLogger.LogError(ex.ToString());
+ private static void ReportException(Exception ex) => DetourLogger.Log(LogLevel.Error, ex.ToString());
private static Type ConvertManagedTypeToIL2CPPType(Type managedType)
{
diff --git a/BepInEx.IL2CPP/IL2CPPChainloader.cs b/BepInEx.IL2CPP/IL2CPPChainloader.cs
index a4ea66b..dd256d0 100644
--- a/BepInEx.IL2CPP/IL2CPPChainloader.cs
+++ b/BepInEx.IL2CPP/IL2CPPChainloader.cs
@@ -91,7 +91,7 @@ public class IL2CPPChainloader : BaseChainloader
Logger.Log(LogLevel.Debug, "Initializing TLS adapters");
Il2CppTlsAdapter.Initialize();
- PreloaderLogger.Log.LogDebug("Runtime invoke patched");
+ PreloaderLogger.Log.Log(LogLevel.Debug, "Runtime invoke patched");
}
private void OnInstallUnityTlsInterface(IntPtr unityTlsInterfaceStruct)
diff --git a/BepInEx.IL2CPP/Preloader.cs b/BepInEx.IL2CPP/Preloader.cs
index f705896..8635668 100644
--- a/BepInEx.IL2CPP/Preloader.cs
+++ b/BepInEx.IL2CPP/Preloader.cs
@@ -91,7 +91,7 @@ public static class Preloader
}
catch (Exception ex)
{
- Log.LogFatal(ex);
+ Log.Log(LogLevel.Fatal, ex);
throw;
}
@@ -100,11 +100,11 @@ public static class Preloader
private static void InitializeUnityVersion()
{
if (TryInitializeUnityVersion(ConfigUnityVersion.Value))
- Log.LogWarning("Unity version obtained from the config.");
+ Log.Log(LogLevel.Warning, "Unity version obtained from the config.");
else if (TryInitializeUnityVersion(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion))
- Log.LogDebug("Unity version obtained from main application module.");
+ Log.Log(LogLevel.Debug, "Unity version obtained from main application module.");
else
- Log.LogError("Running under default Unity version. UnityVersionHandler is not initialized.");
+ Log.Log(LogLevel.Error, "Running under default Unity version. UnityVersionHandler is not initialized.");
}
private static bool TryInitializeUnityVersion(string version)
diff --git a/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs b/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
index c800d22..1808493 100644
--- a/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
+++ b/BepInEx.Preloader.Core/Patching/AssemblyPatcher.cs
@@ -200,7 +200,8 @@ public class AssemblyPatcher : IDisposable
}
catch (Exception e)
{
- Logger.LogError($"Failed to load patchers from type [{patcherPlugin.TypeName}]: {(e is ReflectionTypeLoadException re ? TypeLoader.TypeLoadExceptionToString(re) : e)}");
+ Logger.Log(LogLevel.Error,
+ $"Failed to load patchers from type [{patcherPlugin.TypeName}]: {(e is ReflectionTypeLoadException re ? TypeLoader.TypeLoadExceptionToString(re) : e.ToString())}");
}
var assName = ass.GetName();