Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Suggested Practice for Event Logging View modes: 
User avatar
Member
Member
jasonlancester-gmail - 2/24/2010 11:25:59 PM
   
Suggested Practice for Event Logging
I couldn't find a definitive recommendation for event logging so some time ago I simply started logging exceptions using:

new EventLogProvider().LogEvent("ControlName", "EXCEPTION", exceptionObject);


For some of our sites this works as expected and the event does appear in the event log in CMSDesk/CMSSiteManager. One site in particular, it does not seem to write to the log, ever, and it seems it does not work in all circumstances even in a site where it normally does.

Is the EventLogProvider the appropriate class to use or is there another higher level class we should be using? Is there some other way we should be logging events to the CMS Event Log?

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 3/11/2010 4:42:46 AM
   
RE:Suggested Practice for Event Logging
Hello,

The code seems to be correct. You can just add parameter for siteId so event is logged for appropriate site. If you log more events in one method I would also recommend creating one instance of EventLogProvider and then use this instance:

CMS.EventLog.EventLogProvider evp = new CMS.EventLog.EventLogProvider();
evp.LogEvent("Source", "EventCode", ex, CMS.CMSHelper.CMSContext.CurrentSiteID);


You may optionally debug your code and check if this line has been accessed if you have suspicion that event hasn't been logged.

Best Regards,

Martin Dobsicek