我用hangfire运行进程,重复任务。这些任务设置为每分钟启动一次并处理数据库中的数千行。
我让它们在我的测试环境中顺利运行,直到我在这些方法中添加了 log4net 日志记录。现在 log4net 抛出一个线程错误。
log4net:ERROR Failed to append to appender [AdoNetAppender]
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Monitor.ReliableEnter(Object obj, Boolean& lockTaken)
at System.Threading.Monitor.Enter(Object obj, Boolean& lockTaken)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
at log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(LoggingEvent loggingEvent)
log4net:ERROR Exception while logging
System.Threading.ThreadAbortException: Thread was being aborted.
at log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(LoggingEvent loggingEvent)
at log4net.Repository.Hierarchy.Logger.CallAppenders(LoggingEvent loggingEvent)
at log4net.Repository.Hierarchy.Logger.ForcedLog(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
at log4net.Repository.Hierarchy.Logger.Log(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
log4net:ERROR Failed to append to appender [AdoNetAppender]
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Monitor.ReliableEnter(Object obj, Boolean& lockTaken)
at System.Threading.Monitor.Enter(Object obj, Boolean& lockTaken)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)
at log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(LoggingEvent loggingEvent)
log4net:ERROR Exception while logging
System.Threading.ThreadAbortException: Thread was being aborted.
at log4net.Util.AppenderAttachedImpl.AppendLoopOnAppenders(LoggingEvent loggingEvent)
at log4net.Repository.Hierarchy.Logger.CallAppenders(LoggingEvent loggingEvent)
at log4net.Repository.Hierarchy.Logger.ForcedLog(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
at log4net.Repository.Hierarchy.Logger.Log(Type callerStackBoundaryDeclaringType, Level level, Object message, Exception exception)
不完全确定如何解决这个问题?
我已经读过,对于后台线程,您可以设置 IsBackground=true 并将销毁工作人员,但对我来说,这似乎是在 hangfire 子系统中进行管理。
我更关心从 log4net 修复它或以不同的方式编写方法。请注意,这是测试项目,但在真实环境中我不会直接调用 log4net,它将被包装在 LoggingService 中。对于这个测试,我只是想保持简单。除非我别无选择。