DNN 9.8 - EventLogController 已过时 - 有人有关于如何使用依赖注入方法修复此错误的示例吗?

DNN 9.8 - EventLogController is obsolete - Does anyone have an example on how to use the Dependency Injection method to fix this error?

是否有人可以提供示例来替换 DNN 模块中的旧错误日志记录?

我看过以下文章:

  1. https://dnncommunity.org/forums/aft/1527

我目前收到以下错误:

catch (Exception ex)
    {
      EventLogController logController = new EventLogController();
      logController.AddLog("Problem Getting Product Description, Title, or Image URL.", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
    }

您需要创建启动文件吗? 如果是这样,是否需要为每个模块创建一个启动文件或将其放在根文件夹中?

下面是一些适合我的代码:

using DotNetNuke.Abstractions;
using DotNetNuke.Abstractions.Logging;
using Microsoft.Extensions.DependencyInjection;

namespace myCompany.DNN.Modules.myModule {
   private readonly IEventLogger _eventLogger;
   public class myControl {
      public myControl() {      // this is the constructor of the class
         _eventlogger = DependencyProvider.GetRequiredService<IEventLogger>();
      }
   }

   protected override void someEvent(object sender, EventArgs e) {
      try {
         // some code
      } catch(Exception ex) {
         _eventLogger.AddLog("Problem Getting Product Description, Title, or Image URL.", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
      }
   }
}

这个 article 也很有用...