Does anyone perhaps have an example to replace the old Error logging in DNN module?
I have looked at the following articles:
I currently get the following error:
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?
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...