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

2024-03-30

有人可能有一个示例来替换 DNN 模块中旧的错误日志记录吗?

我看过以下文章:

  1. https://dnncommunity.org/forums/aft/1527 https://dnncommunity.org/forums/aft/1527
  2. 有人在 DNN 版本 9.9 中实现了 DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias 吗? https://stackoverflow.com/questions/66790246/has-anyone-implemented-dotnetnuke-abstractions-portals-iportalaliasinfo-httpalia

I currently get the following error: enter image description here

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 https://www.andrewhoefling.com/Blog/Post/dnn-dependency-injection-webforms-modules也可能有用...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐