2

Does anyone perhaps have an example to replace the old Error logging in DNN module?

I have looked at the following articles:

  1. https://dnncommunity.org/forums/aft/1527
  2. Has anyone implemented DotNetNuke.Abstractions.Portals.IPortalAliasInfo.HttpAlias in DNN version 9.9?

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);
    }

Do you need to create a startup file? If so, do you need to create a startup file for each module or put it in the root folder?

Tig7r
  • 525
  • 1
  • 4
  • 21

1 Answers1

2

Here is some code that works for me:

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);
      }
   }
}

And this article could be useful, too...

Michael Tobisch
  • 1,034
  • 6
  • 15