---
title: Event log
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Logging events

```csharp

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

```

[> Back to list of examples](#eventlog-toc)

### Working with events (sending events by email)

```csharp

// 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](#eventlog-toc)

### Clearing the event log

```csharp

// 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](#eventlog-toc)
