mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
chore: convert Dalamud to file-scoped namespaces
This commit is contained in:
parent
b093323acc
commit
987ff8dc8f
368 changed files with 55081 additions and 55450 deletions
|
|
@ -3,140 +3,139 @@ using System;
|
|||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud.Logging.Internal
|
||||
namespace Dalamud.Logging.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Class offering various methods to allow for logging in Dalamud modules.
|
||||
/// </summary>
|
||||
public class ModuleLog
|
||||
{
|
||||
private readonly string moduleName;
|
||||
private readonly ILogger moduleLogger;
|
||||
|
||||
/// <summary>
|
||||
/// Class offering various methods to allow for logging in Dalamud modules.
|
||||
/// Initializes a new instance of the <see cref="ModuleLog"/> class.
|
||||
/// This class can be used to prefix logging messages with a Dalamud module name prefix. For example, "[PLUGINR] ...".
|
||||
/// </summary>
|
||||
public class ModuleLog
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
public ModuleLog(string? moduleName)
|
||||
{
|
||||
private readonly string moduleName;
|
||||
private readonly ILogger moduleLogger;
|
||||
// FIXME: Should be namespaced better, e.g. `Dalamud.PluginLoader`, but that becomes a relatively large
|
||||
// change.
|
||||
this.moduleName = moduleName ?? "DalamudInternal";
|
||||
this.moduleLogger = Log.ForContext("SourceContext", this.moduleName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModuleLog"/> class.
|
||||
/// This class can be used to prefix logging messages with a Dalamud module name prefix. For example, "[PLUGINR] ...".
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
public ModuleLog(string? moduleName)
|
||||
{
|
||||
// FIXME: Should be namespaced better, e.g. `Dalamud.PluginLoader`, but that becomes a relatively large
|
||||
// change.
|
||||
this.moduleName = moduleName ?? "DalamudInternal";
|
||||
this.moduleLogger = Log.ForContext("SourceContext", this.moduleName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Information, messageTemplate, exception, values);
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Error, messageTemplate, exception, values);
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
private void WriteLog(LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
|
||||
{
|
||||
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
|
||||
// formatter.
|
||||
this.moduleLogger.Write(
|
||||
level,
|
||||
exception: exception,
|
||||
messageTemplate: $"[{this.moduleName}] {messageTemplate}",
|
||||
values);
|
||||
}
|
||||
private void WriteLog(LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
|
||||
{
|
||||
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
|
||||
// formatter.
|
||||
this.moduleLogger.Write(
|
||||
level,
|
||||
exception: exception,
|
||||
messageTemplate: $"[{this.moduleName}] {messageTemplate}",
|
||||
values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,49 +3,48 @@ using System;
|
|||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud.Logging.Internal
|
||||
namespace Dalamud.Logging.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Serilog event sink.
|
||||
/// </summary>
|
||||
internal class SerilogEventSink : ILogEventSink
|
||||
{
|
||||
private static SerilogEventSink instance;
|
||||
private readonly IFormatProvider formatProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Serilog event sink.
|
||||
/// Initializes a new instance of the <see cref="SerilogEventSink"/> class.
|
||||
/// </summary>
|
||||
internal class SerilogEventSink : ILogEventSink
|
||||
/// <param name="formatProvider">Logging format provider.</param>
|
||||
private SerilogEventSink(IFormatProvider formatProvider)
|
||||
{
|
||||
private static SerilogEventSink instance;
|
||||
private readonly IFormatProvider formatProvider;
|
||||
this.formatProvider = formatProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SerilogEventSink"/> class.
|
||||
/// </summary>
|
||||
/// <param name="formatProvider">Logging format provider.</param>
|
||||
private SerilogEventSink(IFormatProvider formatProvider)
|
||||
/// <summary>
|
||||
/// Event on a log line being emitted.
|
||||
/// </summary>
|
||||
public event EventHandler<(string Line, LogEvent LogEvent)>? LogLine;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default instance.
|
||||
/// </summary>
|
||||
public static SerilogEventSink Instance => instance ??= new SerilogEventSink(null);
|
||||
|
||||
/// <summary>
|
||||
/// Emit a log event.
|
||||
/// </summary>
|
||||
/// <param name="logEvent">Log event to be emitted.</param>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
var message = logEvent.RenderMessage(this.formatProvider);
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
this.formatProvider = formatProvider;
|
||||
message += "\n" + logEvent.Exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event on a log line being emitted.
|
||||
/// </summary>
|
||||
public event EventHandler<(string Line, LogEvent LogEvent)>? LogLine;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default instance.
|
||||
/// </summary>
|
||||
public static SerilogEventSink Instance => instance ??= new SerilogEventSink(null);
|
||||
|
||||
/// <summary>
|
||||
/// Emit a log event.
|
||||
/// </summary>
|
||||
/// <param name="logEvent">Log event to be emitted.</param>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
var message = logEvent.RenderMessage(this.formatProvider);
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
message += "\n" + logEvent.Exception;
|
||||
}
|
||||
|
||||
this.LogLine?.Invoke(this, (message, logEvent));
|
||||
}
|
||||
this.LogLine?.Invoke(this, (message, logEvent));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,238 +7,237 @@ using System.Threading.Tasks;
|
|||
|
||||
using Dalamud.Game;
|
||||
|
||||
namespace Dalamud.Logging.Internal
|
||||
namespace Dalamud.Logging.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Class responsible for tracking asynchronous tasks.
|
||||
/// </summary>
|
||||
[ServiceManager.EarlyLoadedService]
|
||||
internal class TaskTracker : IDisposable, IServiceType
|
||||
{
|
||||
/// <summary>
|
||||
/// Class responsible for tracking asynchronous tasks.
|
||||
/// </summary>
|
||||
[ServiceManager.EarlyLoadedService]
|
||||
internal class TaskTracker : IDisposable, IServiceType
|
||||
private static readonly ModuleLog Log = new("TT");
|
||||
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
||||
private static readonly ConcurrentQueue<TaskInfo> NewlyCreatedTasks = new();
|
||||
private static bool clearRequested = false;
|
||||
|
||||
[ServiceManager.ServiceDependency]
|
||||
private readonly Framework framework = Service<Framework>.Get();
|
||||
|
||||
private MonoMod.RuntimeDetour.Hook? scheduleAndStartHook;
|
||||
private bool enabled = false;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private TaskTracker()
|
||||
{
|
||||
private static readonly ModuleLog Log = new("TT");
|
||||
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
||||
private static readonly ConcurrentQueue<TaskInfo> NewlyCreatedTasks = new();
|
||||
private static bool clearRequested = false;
|
||||
|
||||
[ServiceManager.ServiceDependency]
|
||||
private readonly Framework framework = Service<Framework>.Get();
|
||||
|
||||
private MonoMod.RuntimeDetour.Hook? scheduleAndStartHook;
|
||||
private bool enabled = false;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private TaskTracker()
|
||||
{
|
||||
#if DEBUG
|
||||
this.Enable();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of tracked tasks.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<TaskInfo> Tasks => TrackedTasksInternal.ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Clear the list of tracked tasks.
|
||||
/// </summary>
|
||||
public static void Clear() => clearRequested = true;
|
||||
|
||||
/// <summary>
|
||||
/// Update the tracked data.
|
||||
/// </summary>
|
||||
public static void UpdateData()
|
||||
{
|
||||
if (clearRequested)
|
||||
{
|
||||
TrackedTasksInternal.Clear();
|
||||
clearRequested = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of tracked tasks.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<TaskInfo> Tasks => TrackedTasksInternal.ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Clear the list of tracked tasks.
|
||||
/// </summary>
|
||||
public static void Clear() => clearRequested = true;
|
||||
|
||||
/// <summary>
|
||||
/// Update the tracked data.
|
||||
/// </summary>
|
||||
public static void UpdateData()
|
||||
var i = 0;
|
||||
var pruned = 0;
|
||||
// Prune old tasks. Technically a memory "leak" that grows infinitely otherwise.
|
||||
while (i < TrackedTasksInternal.Count)
|
||||
{
|
||||
if (clearRequested)
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.IsCompleted && !taskInfo.IsBeingViewed && TrackedTasksInternal.Count > 1000)
|
||||
{
|
||||
TrackedTasksInternal.Clear();
|
||||
clearRequested = false;
|
||||
TrackedTasksInternal.RemoveAt(i);
|
||||
pruned++;
|
||||
continue;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var pruned = 0;
|
||||
// Prune old tasks. Technically a memory "leak" that grows infinitely otherwise.
|
||||
while (i < TrackedTasksInternal.Count)
|
||||
{
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.IsCompleted && !taskInfo.IsBeingViewed && TrackedTasksInternal.Count > 1000)
|
||||
{
|
||||
TrackedTasksInternal.RemoveAt(i);
|
||||
pruned++;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
i++;
|
||||
// if (pruned > 0)
|
||||
// Log.Debug($"Pruned {pruned} tasks");
|
||||
|
||||
// Consume from a queue to prevent iteration errors
|
||||
while (NewlyCreatedTasks.TryDequeue(out var newTask))
|
||||
{
|
||||
TrackedTasksInternal.Add(newTask);
|
||||
}
|
||||
|
||||
// Update each task
|
||||
for (i = 0; i < TrackedTasksInternal.Count; i++)
|
||||
{
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.Task == null)
|
||||
continue;
|
||||
|
||||
taskInfo.IsCompleted = taskInfo.Task.IsCompleted;
|
||||
taskInfo.IsFaulted = taskInfo.Task.IsFaulted;
|
||||
taskInfo.IsCanceled = taskInfo.Task.IsCanceled;
|
||||
taskInfo.IsCompletedSuccessfully = taskInfo.Task.IsCompletedSuccessfully;
|
||||
taskInfo.Status = taskInfo.Task.Status;
|
||||
|
||||
if (taskInfo.IsCompleted || taskInfo.IsFaulted || taskInfo.IsCanceled ||
|
||||
taskInfo.IsCompletedSuccessfully)
|
||||
{
|
||||
taskInfo.Exception = taskInfo.Task.Exception;
|
||||
|
||||
taskInfo.Task = null;
|
||||
taskInfo.FinishTime = DateTime.Now;
|
||||
}
|
||||
|
||||
// if (pruned > 0)
|
||||
// Log.Debug($"Pruned {pruned} tasks");
|
||||
|
||||
// Consume from a queue to prevent iteration errors
|
||||
while (NewlyCreatedTasks.TryDequeue(out var newTask))
|
||||
{
|
||||
TrackedTasksInternal.Add(newTask);
|
||||
}
|
||||
|
||||
// Update each task
|
||||
for (i = 0; i < TrackedTasksInternal.Count; i++)
|
||||
{
|
||||
var taskInfo = TrackedTasksInternal[i];
|
||||
if (taskInfo.Task == null)
|
||||
continue;
|
||||
|
||||
taskInfo.IsCompleted = taskInfo.Task.IsCompleted;
|
||||
taskInfo.IsFaulted = taskInfo.Task.IsFaulted;
|
||||
taskInfo.IsCanceled = taskInfo.Task.IsCanceled;
|
||||
taskInfo.IsCompletedSuccessfully = taskInfo.Task.IsCompletedSuccessfully;
|
||||
taskInfo.Status = taskInfo.Task.Status;
|
||||
|
||||
if (taskInfo.IsCompleted || taskInfo.IsFaulted || taskInfo.IsCanceled ||
|
||||
taskInfo.IsCompletedSuccessfully)
|
||||
{
|
||||
taskInfo.Exception = taskInfo.Task.Exception;
|
||||
|
||||
taskInfo.Task = null;
|
||||
taskInfo.FinishTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables TaskTracker.
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
if (this.enabled)
|
||||
return;
|
||||
|
||||
this.ApplyPatch();
|
||||
|
||||
this.framework.Update += this.FrameworkOnUpdate;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.scheduleAndStartHook?.Dispose();
|
||||
|
||||
this.framework.Update -= this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
private static bool AddToActiveTasksHook(Func<Task, bool> orig, Task self)
|
||||
{
|
||||
orig(self);
|
||||
|
||||
var trace = new StackTrace();
|
||||
NewlyCreatedTasks.Enqueue(new TaskInfo
|
||||
{
|
||||
Task = self,
|
||||
Id = self.Id,
|
||||
StackTrace = trace,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FrameworkOnUpdate(Framework framework)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
private void ApplyPatch()
|
||||
{
|
||||
var targetType = typeof(Task);
|
||||
|
||||
var debugField = targetType.GetField("s_asyncDebuggingEnabled", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
debugField.SetValue(null, true);
|
||||
|
||||
Log.Information("s_asyncDebuggingEnabled: {0}", debugField.GetValue(null));
|
||||
|
||||
var targetMethod = targetType.GetMethod("AddToActiveTasks", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
var patchMethod = typeof(TaskTracker).GetMethod(nameof(AddToActiveTasksHook), BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
if (targetMethod == null)
|
||||
{
|
||||
Log.Error("AddToActiveTasks TargetMethod null!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (patchMethod == null)
|
||||
{
|
||||
Log.Error("AddToActiveTasks PatchMethod null!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.scheduleAndStartHook = new MonoMod.RuntimeDetour.Hook(targetMethod, patchMethod);
|
||||
|
||||
Log.Information("AddToActiveTasks Hooked!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a tracked task.
|
||||
/// </summary>
|
||||
internal class TaskInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the tracked task.
|
||||
/// </summary>
|
||||
public Task? Task { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the task.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the stack trace of where the task was started.
|
||||
/// </summary>
|
||||
public StackTrace? StackTrace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was completed.
|
||||
/// </summary>
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task faulted.
|
||||
/// </summary>
|
||||
public bool IsFaulted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was canceled.
|
||||
/// </summary>
|
||||
public bool IsCanceled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was completed successfully.
|
||||
/// </summary>
|
||||
public bool IsCompletedSuccessfully { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this task is being viewed.
|
||||
/// </summary>
|
||||
public bool IsBeingViewed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the task.
|
||||
/// </summary>
|
||||
public TaskStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the start time of the task.
|
||||
/// </summary>
|
||||
public DateTime StartTime { get; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the end time of the task.
|
||||
/// </summary>
|
||||
public DateTime FinishTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that occurred within the task.
|
||||
/// </summary>
|
||||
public AggregateException? Exception { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables TaskTracker.
|
||||
/// </summary>
|
||||
public void Enable()
|
||||
{
|
||||
if (this.enabled)
|
||||
return;
|
||||
|
||||
this.ApplyPatch();
|
||||
|
||||
this.framework.Update += this.FrameworkOnUpdate;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.scheduleAndStartHook?.Dispose();
|
||||
|
||||
this.framework.Update -= this.FrameworkOnUpdate;
|
||||
}
|
||||
|
||||
private static bool AddToActiveTasksHook(Func<Task, bool> orig, Task self)
|
||||
{
|
||||
orig(self);
|
||||
|
||||
var trace = new StackTrace();
|
||||
NewlyCreatedTasks.Enqueue(new TaskInfo
|
||||
{
|
||||
Task = self,
|
||||
Id = self.Id,
|
||||
StackTrace = trace,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FrameworkOnUpdate(Framework framework)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
private void ApplyPatch()
|
||||
{
|
||||
var targetType = typeof(Task);
|
||||
|
||||
var debugField = targetType.GetField("s_asyncDebuggingEnabled", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
debugField.SetValue(null, true);
|
||||
|
||||
Log.Information("s_asyncDebuggingEnabled: {0}", debugField.GetValue(null));
|
||||
|
||||
var targetMethod = targetType.GetMethod("AddToActiveTasks", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
var patchMethod = typeof(TaskTracker).GetMethod(nameof(AddToActiveTasksHook), BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
if (targetMethod == null)
|
||||
{
|
||||
Log.Error("AddToActiveTasks TargetMethod null!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (patchMethod == null)
|
||||
{
|
||||
Log.Error("AddToActiveTasks PatchMethod null!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.scheduleAndStartHook = new MonoMod.RuntimeDetour.Hook(targetMethod, patchMethod);
|
||||
|
||||
Log.Information("AddToActiveTasks Hooked!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a tracked task.
|
||||
/// </summary>
|
||||
internal class TaskInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the tracked task.
|
||||
/// </summary>
|
||||
public Task? Task { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the task.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the stack trace of where the task was started.
|
||||
/// </summary>
|
||||
public StackTrace? StackTrace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was completed.
|
||||
/// </summary>
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task faulted.
|
||||
/// </summary>
|
||||
public bool IsFaulted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was canceled.
|
||||
/// </summary>
|
||||
public bool IsCanceled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task was completed successfully.
|
||||
/// </summary>
|
||||
public bool IsCompletedSuccessfully { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this task is being viewed.
|
||||
/// </summary>
|
||||
public bool IsBeingViewed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the task.
|
||||
/// </summary>
|
||||
public TaskStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the start time of the task.
|
||||
/// </summary>
|
||||
public DateTime StartTime { get; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the end time of the task.
|
||||
/// </summary>
|
||||
public DateTime FinishTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that occurred within the task.
|
||||
/// </summary>
|
||||
public AggregateException? Exception { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,258 +4,257 @@ using System.Reflection;
|
|||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud.Logging
|
||||
namespace Dalamud.Logging;
|
||||
|
||||
/// <summary>
|
||||
/// Class offering various static methods to allow for logging in plugins.
|
||||
/// </summary>
|
||||
public static class PluginLog
|
||||
{
|
||||
#region "Log" prefixed Serilog style methods
|
||||
|
||||
/// <summary>
|
||||
/// Class offering various static methods to allow for logging in plugins.
|
||||
/// Log a templated message to the in-game debug log.
|
||||
/// </summary>
|
||||
public static class PluginLog
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Log(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Log(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogVerbose(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogVerbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogDebug(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogDebug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogInformation(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogInformation(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogWarning(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogWarning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogError(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogError(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogFatal(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogFatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serilog style methods
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
#endregion
|
||||
|
||||
private static ILogger GetPluginLogger(string? pluginName)
|
||||
{
|
||||
#region "Log" prefixed Serilog style methods
|
||||
return Serilog.Log.ForContext("SourceContext", pluginName ?? string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Log(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
private static void WriteLog(string? pluginName, LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
|
||||
{
|
||||
var pluginLogger = GetPluginLogger(pluginName);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Log(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogVerbose(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogVerbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogDebug(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogDebug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogInformation(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogInformation(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogWarning(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogWarning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogError(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogError(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogFatal(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void LogFatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serilog style methods
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, null, values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values);
|
||||
|
||||
#endregion
|
||||
|
||||
private static ILogger GetPluginLogger(string? pluginName)
|
||||
{
|
||||
return Serilog.Log.ForContext("SourceContext", pluginName ?? string.Empty);
|
||||
}
|
||||
|
||||
private static void WriteLog(string? pluginName, LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
|
||||
{
|
||||
var pluginLogger = GetPluginLogger(pluginName);
|
||||
|
||||
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
|
||||
// formatter.
|
||||
pluginLogger.Write(
|
||||
level,
|
||||
exception: exception,
|
||||
messageTemplate: $"[{pluginName}] {messageTemplate}",
|
||||
values);
|
||||
}
|
||||
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
|
||||
// formatter.
|
||||
pluginLogger.Write(
|
||||
level,
|
||||
exception: exception,
|
||||
messageTemplate: $"[{pluginName}] {messageTemplate}",
|
||||
values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue