AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. Configuration
  3. Event log

Event log


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Logging events
  • Logging events using LogEvent
  • Working with events (sending events by email)
  • Clearing the event log

Logging events

C#
IEventLogService eventLog = Service.Resolve<IEventLogService>();

// In case of database outage, the system buffers all logged events in-memory until the database is available. 
// You do not need to buffer or check for database availability in custom code.

// Logs an information event into the event log
eventLog.LogInformation("API Example Info", "APIEXAMPLE", eventDescription: "Test information event.");

// Logs a warning event into the event log
eventLog.LogWarning("API Example Warning", "APIEXAMPLE", eventDescription: "Test warning event.");

// Logs an error event into the event log
eventLog.LogError("API Example Error", "APIEXAMPLE", eventDescription: "Test error event.");

// Logs an exception into the event log
eventLog.LogException("API Example Exception", "APIEXAMPLE", new Exception(), additionalMessage: "Test exception event.");
> Back to list of examples

Logging events using LogEvent

C#
IEventLogService eventLog = Service.Resolve<IEventLogService>();

// Prepares an EventLogData object that holds all information about the event being logged
EventLogData eventData = new EventLogData(EventTypeEnum.Information, "API Example", "APIEXAMPLE")
{
    SiteID = SiteContext.CurrentSiteID,
    EventTime = DateTime.Now,
    EventDescription = "Logging a sample event to the event log."
};


// Logs the event into the event log
eventLog.LogEvent(eventData);
> Back to list of examples

Working with events (sending events by email)

C#
// Gets all error events logged in the past day 
var errors = EventLogInfo.Provider.Get()
                                .WhereEquals("EventType", EventType.ERROR)                                          
                                .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(1)));

if (errors.Count > 0)
{
    // Creates the email message
    EmailMessage msg = new EmailMessage()
    {
        From = "system@localhost.local",
        Recipients = "admin@localhost.local",
        Subject = "Xperience Errors (" + errors.Count + ")",
        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

C#
// Clears the event log for the current site
EventLogHelper.ClearEventLog(MembershipContext.AuthenticatedUser.UserID, MembershipContext.AuthenticatedUser.UserName, RequestContext.UserHostAddress, SiteContext.CurrentSiteID);
> Back to list of examples