diff --git a/Shared/Extensions/GeneralExtension.cs b/Shared/Extensions/GeneralExtension.cs
new file mode 100644
index 0000000..4187af5
--- /dev/null
+++ b/Shared/Extensions/GeneralExtension.cs
@@ -0,0 +1,15 @@
+namespace MeloongCore.Extensions;
+public static class GeneralExtension {
+
+ ///
+ /// 判断对象是否为指定泛型类型的实例。
+ ///
+ public static bool IsGenericInstanceOf(this object? instance, Type genericTypeDefinition) {
+ if (instance is null) return false;
+ for (var type = instance.GetType(); type is not null; type = type.BaseType) {
+ if (type.IsGenericType && type.GetGenericTypeDefinition() == genericTypeDefinition) return true;
+ }
+ return false;
+ }
+
+}
diff --git a/Shared/General/Logger.cs b/Shared/General/Logger.cs
index a9b3172..140af2a 100644
--- a/Shared/General/Logger.cs
+++ b/Shared/General/Logger.cs
@@ -219,7 +219,10 @@ public class BaseLogger {
.Join("\r\n");
}
public static string GetLogPrefix(LogLevel level, string filePath)
- => $"{DateTime.Now:HH':'mm':'ss'.'fff} {level.ToString().First()} {(Thread.CurrentThread.Name is null ? "" : $"<{Thread.CurrentThread.ManagedThreadId} · {Thread.CurrentThread.Name}> ")}[{PathUtils.GetLastPart(filePath).BeforeFirst(".")}] ";
+ => $"{DateTime.Now:HH':'mm':'ss'.'fff} {level.ToString().First()} {
+ (Thread.CurrentThread.Name is not null ? $"<{Thread.CurrentThread.ManagedThreadId} · {Thread.CurrentThread.Name}> " :
+ (Thread.CurrentThread.IsThreadPoolThread ? " " : ""))}[{
+ PathUtils.GetLastPart(filePath).BeforeFirst(".")}] ";
///
/// 执行 。
diff --git a/Shared/General/Workers/RedoableWorker.cs b/Shared/General/Workers/RedoableWorker.cs
index 7bd11cf..d283bba 100644
--- a/Shared/General/Workers/RedoableWorker.cs
+++ b/Shared/General/Workers/RedoableWorker.cs
@@ -33,12 +33,12 @@ public interface IWorker {
ProgressProvider Progress { get; }
}
-// TODO: 现在的可观测性不佳,考虑增加调用方信息以及自身名称等,输出到日志,例如 CallerArgumentExpression
///
/// 可合并和重启的工作器。
/// 在工作负载运行期间多次调用 会取消当前负载并使用最新令牌重新执行;多次调用也只重新执行一次。
///
-public abstract class RedoableWorkerBase(Func workload, ProgressProvider? progress = null) : IWorker {
+public abstract class RedoableWorkerBase(Func workload,
+ ProgressProvider? progress = null, [CallerMemberName] string creatorMemberName = "") : IWorker {
// ============================================ 状态与事件 ============================================
@@ -93,6 +93,7 @@ public abstract class RedoableWorkerBase(Func(Func(Func(Func(Func(Func
public class RedoableWorker : RedoableWorkerBase {
- public RedoableWorker(Func workload) : base(workload) { }
- public RedoableWorker(Func workload) : base((c, _) => workload(c)) { }
- public RedoableWorker(Func workload) : base((_, _) => workload()) { }
+ public RedoableWorker(Func workload, [CallerMemberName] string creatorMemberName = "")
+ : base(workload, creatorMemberName: creatorMemberName) { }
+ public RedoableWorker(Func workload, [CallerMemberName] string creatorMemberName = "")
+ : base((c, _) => workload(c), creatorMemberName: creatorMemberName) { }
+ public RedoableWorker(Func workload, [CallerMemberName] string creatorMemberName = "")
+ : base((_, _) => workload(), creatorMemberName: creatorMemberName) { }
}
///
public class RedoableWorker : RedoableWorkerBase