Search code examples
dotnetnuke2sxc

How to log data in DNN admin log or server event log


I simply want to debug a controller but I can't watch the variables I get from 2sxc functions.

I tried to log varables via Log4Net writting :

private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(MyClassName));

but the type ILog is not known in a 2sxc controller. Am I missing a reference?

I also found this snippet:

using DotNetNuke.Services.Log.EventLog;

var objEventLog = new EventLogController();
objEventLog.AddLog("Sample Message", "Something Interesting Happened!", PortalSettings, UserId, EventLogController.EventLogType.ADMIN_ALERT)

But I don't know what to send to "PortalSettings" and I don't any clue in the helpers of the 2sxc programming interface.

How do you guys debug 2sxc controllers and log events (not only for debuging)?

Thank you for your help!

Credit of these snippets: Scott McCulloch (https://www.smcculloch.com/code/logging-to-the-dnn-event-log)


Solution

  • This gives part of the answer: http://www.dnnsoftware.com/community-blog/cid/141723/using-log4net-with-dotnetnuke. And, it looks like the namespace is DotNetNuke.Instrumentation.

    As for PortalSettings, that's the portal settings for your portal. I think that you'd need to reference DotNetNuke.Entities.Portals, and then use PortalController to retrieve the portal settings object.