Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to add custom Event Log Type?How to add custom Event Log Type?
Previous
 
Next
New Post
5/11/2006 3:22 AM
 

I want to create custom Event Log Type for my module and write my messages to EventLogTypes table and then view them using DNN Log Viewer.
Is any documentation/tips, how to do it, available?

Regards,

Michael Freidgeim
Blog: http://geekswithblogs.net/mnf/


Michael Freidgeim http://geekswithblogs.net/mnf
 
New Post
5/15/2006 8:31 AM
 

We haven't produced any documentation  as far as I know (though the DNN book does cover the event/exception's API's so that's a good resource to start with). I've added a new exception type to the next release, SecurityException, so that it can be utilised in a number of locations, it's not an easy task, and one best dealt with in the upgrade.vb at present, until the next release when the eventing model will make items like this a bit easier.

Anyway, the code I used is as follows:

1. adding the exception type in upgrade.vb (I created an xml file [SecurityExceptionTemplate.xml.resources] with the details, both the definition, and the event schedule details - you can look at the other .xml.resources file to work out the necessary details)

                        'add new SecurityException
                        Dim objSecLogController As New Log.EventLog.LogController
                        Dim xmlSecDoc As New XmlDocument
                        Dim xmlSecConfigFile As String = Common.Globals.HostMapPath + "Logs\LogConfig\SecurityExceptionTemplate.xml.resources"
                        Try
                            xmlSecDoc.Load(xmlSecConfigFile)
                        Catch exc As FileNotFoundException
                            '  xmlConfigFile = Common.Globals.HostMapPath + "Logs\LogConfig\LogConfigTemplate.xml.resources"
                            ' xmlDoc.Load(xmlConfigFile)
                        End Try
                        Dim LogType As XmlNodeList = xmlSecDoc.SelectNodes("/LogConfig/LogTypes/LogType")
                        Dim LogTypeInfo As XmlNode
                        For Each LogTypeInfo In LogType
                            Dim objLogTypeInfo As New Log.EventLog.LogTypeInfo
                            objLogTypeInfo.LogTypeKey = LogTypeInfo.Attributes("LogTypeKey").Value
                            objLogTypeInfo.LogTypeFriendlyName = LogTypeInfo.Attributes("LogTypeFriendlyName").Value
                            objLogTypeInfo.LogTypeDescription = LogTypeInfo.Attributes("LogTypeDescription").Value
                            objLogTypeInfo.LogTypeCSSClass = LogTypeInfo.Attributes("LogTypeCSSClass").Value
                            objLogTypeInfo.LogTypeOwner = LogTypeInfo.Attributes("LogTypeOwner").Value
                            objSecLogController.AddLogType(objLogTypeInfo)
                        Next

                        Dim LogTypeConfig As XmlNodeList = xmlSecDoc.SelectNodes("/LogConfig/LogTypeConfig")
                        Dim LogTypeConfigInfo As XmlNode
                        For Each LogTypeConfigInfo In LogTypeConfig
                            Dim objLogTypeConfig As New Log.EventLog.LogTypeConfigInfo
                            objLogTypeConfig.EmailNotificationIsActive = Convert.ToBoolean(IIf(LogTypeConfigInfo.Attributes("EmailNotificationStatus").Value = "On", True, False))
                            objLogTypeConfig.KeepMostRecent = LogTypeConfigInfo.Attributes("KeepMostRecent").Value
                            objLogTypeConfig.LoggingIsActive = Convert.ToBoolean(IIf(LogTypeConfigInfo.Attributes("LoggingStatus").Value = "On", True, False))
                            objLogTypeConfig.LogTypeKey = LogTypeConfigInfo.Attributes("LogTypeKey").Value
                            objLogTypeConfig.LogTypePortalID = LogTypeConfigInfo.Attributes("LogTypePortalID").Value
                            objLogTypeConfig.MailFromAddress = LogTypeConfigInfo.Attributes("MailFromAddress").Value
                            objLogTypeConfig.MailToAddress = LogTypeConfigInfo.Attributes("MailToAddress").Value
                            objLogTypeConfig.NotificationThreshold = Convert.ToInt32(LogTypeConfigInfo.Attributes("NotificationThreshold").Value)
                            objLogTypeConfig.NotificationThresholdTime = Convert.ToInt32(LogTypeConfigInfo.Attributes("NotificationThresholdTime").Value)
                            objLogTypeConfig.NotificationThresholdTimeType = CType(LogTypeConfigInfo.Attributes("NotificationThresholdTimeType").Value, Services.Log.EventLog.LogTypeConfigInfo.NotificationThresholdTimeTypes)
                            objSecLogController.AddLogTypeConfigInfo(objLogTypeConfig)
                        Next

2. Create a new event type - look @ components\providers\logging\event logging\EventLogController.vb, you'll need to edit the ENUM and add your new EventLogType.

3. edit admin\logging\logviewer.ascx if necessary with a unique colour for your new event.

Alternatively,  piggyback on one of the existing events- most support passing a message, as well as variours serialised data formats, so you could craft the message to contain your module name at the start.

Cathal


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
5/29/2006 1:24 AM
 

Cathal,

Thank you for your informative reply. It pointed me to the right direction.
1. I've added my custom event types just by inserting extra records to dnn_EventLogTypes.

2.Also adding  new EventLogType to EventLogController.EventLogType is OPTIONAL. Even not all core event types are listed in ENUM. I didn't want to modify core class for each custom event type, that any developer can create.
Fortunately, there are couple EventLogController.AddLog overloads that expect LogTypeKey As String , which  make possible to avoid modifiing EventLogController.EventLogType enum.

3. I also beleive that it is possible to add extra color classes for new event by adding the new css classes to global portal.css whithout modifiing core admin\logging\logviewer.ascx. (I haven't tried this,because current css classes are sufficient for my purposes).  

 

 


Michael Freidgeim http://geekswithblogs.net/mnf
 
New Post
6/29/2010 11:11 PM
 
/// <summary>
/// Creates a log type and config
/// </summary>
/// <param name="logTypeKey">Unique key for the event type</param>
/// <param name="logTypeFriendlyName">Display in log viewer</param>
/// <param name="logTypeDescription">Description</param>
/// <param name="logTypeCSSClass">The CSS class to render in the event viewer</param>
/// <param name="logTypeOwner">The event class type</param>
public static void CreateLogType(string logTypeKey, string logTypeFriendlyName, string logTypeDescription, string logTypeCSSClass, string logTypeOwner)
{
    try
    {
        DotNetNuke.Services.Log.EventLog.LogController lc = new DotNetNuke.Services.Log.EventLog.LogController();
        DotNetNuke.Services.Log.EventLog.LogTypeInfo lti = new DotNetNuke.Services.Log.EventLog.LogTypeInfo();
        lti.LogTypeCSSClass = logTypeCSSClass;
        lti.LogTypeDescription = logTypeDescription;
        lti.LogTypeFriendlyName = logTypeFriendlyName;
        lti.LogTypeOwner = logTypeOwner;// "DotNetNuke.Logging.EventLogType";
        lti.LogTypeKey = logTypeKey;
        lc.AddLogType(lti);
        DotNetNuke.Services.Log.EventLog.LogTypeConfigInfo ltci = new DotNetNuke.Services.Log.EventLog.LogTypeConfigInfo();
        ltci.LogTypeKey = logTypeKey;
        ltci.LoggingIsActive = true;
        ltci.MailFromAddress = "";
        ltci.MailToAddress = "";
        ltci.EmailNotificationIsActive = false;
        lc.AddLogTypeConfigInfo(ltci);
    }
    catch (Exception ex)
    {
        DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
    }
}

Since I just had to set this up myself (DNN 5.4.2) this creates the log type and enables it, but without email notifications
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to add custom Event Log Type?How to add custom Event Log Type?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out