Logging to the DNN event log

How to log or print useful information to the DNN event log in C#.

Gus Beare

Logging to the dnn event log useful information such as Mandrill responses

I have recently been using Mandrill for various email solutions. If you're not familiar with it then it's a must. I love it for these reasons:

  1. Mandrill provides a free account which gives small developers like myself access to powerful mail servers and 12,000 free email sends per month. More than enough for my needs.
  2. All emails are logged so you can see what happened to every email sent.
  3. You can use templates to build emails and post token data which is injected into the templates before the email is sent.
  4. Mandrill provides link tracking so you can see how users are interacting with your email links.

I have started using Mandrill for newsletter campaigns as well as basic message sending from DNN websites using Mandrill SMTP servers. For DNN module development I am using Easy Emailer for Mandrill which is simple to use and works very well.

One thing that is nice about using Easy Emailer is that it provides simple access to the response from Mandrill after emails are sent. I thought it would be useful to log this to the event log in DNN so I can be sure that Mandrill is receiving and processing the requests. Here is the code:

var eventLog = new EventLogController();
var logInfo = new LogInfo
    LogUserID = UserId,
    LogPortalID = portalId,
    LogTypeKey = EventLogController.EventLogType.ADMIN_ALERT.ToString()

logInfo.AddProperty("MandrillResponse=", response.Message);
logInfo.AddProperty("UserId=", UserId.ToString());
logInfo.AddProperty("UserName=", email);
logInfo.AddProperty("Number of Email sent=", response.EmailSent.Count.ToString());
logInfo.AddProperty("Number of email failures=", response.EmailFailures.Count.ToString());