Is this really the version you are looking for? Kentico 9 documentation is no longer updated. Use the switch in the header to choose your Kentico version.

Event log

List of examples:

Logging events

// Logs an information event into the event log
EventLogProvider.LogEvent(EventType.INFORMATION, "API Example", "APIEXAMPLE", eventDescription: "Testing event logging.");

> Back to list of examples

Working with events (sending events by email)

// Gets all error events logged in the past day 
var errors = EventLogProvider.GetEvents()
								.WhereEquals("EventType", "E")											
								.WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(1)));

if (errors.Count > 0)
{
	// Creates the email message
	EmailMessage msg = new EmailMessage();

	msg.From = "system@localhost.local";
	msg.Recipients = "admin@localhost.local";
	msg.Subject = "Kentico Errors (" + errors.Count + ")";
	msg.Body = "<html><body><ul>";
	
	// Creates a list of the errors
	foreach (EventLogInfo errorEvent in errors)
	{
		msg.Body += String.Format("<li>{0} - {1} - {2}</li>", errorEvent.EventType, errorEvent.EventCode, errorEvent.EventDescription.Substring(0, 100));
	}

	msg.Body += "</ul></body></html>";

	// Sends out the email message
	EmailSender.SendEmail(msg);
}

> Back to list of examples

Clearing the event log

// Clears the event log for the current site
EventLogProvider.ClearEventLog(MembershipContext.AuthenticatedUser.UserID, MembershipContext.AuthenticatedUser.UserName, RequestContext.UserHostAddress, SiteContext.CurrentSiteID);

> Back to list of examples